stop extra lines from printing

P

pauliecat

having all sorts of problems extracting the data. The file I am
extracting on is library catalog records. For instance sometimes I get
the subject printing in the wrong record, or blank lines between each
subject (some records have more than one subject field)

eg: Author Joe Blow
Title Fishing in a coal mine
SUBJ Fishing
SUBJ Coal mines

I'll get results like this
Author Joe Blow
Title Fishing in a coal mine
SUBJ Fishing

SUBJ Coal mines

I'd like to be able for instance keep things together and then have a
blank line between the last element of the first record and a space
between the start of the next record: Here is the script

my $title;
my $author;
my $call;
my $subj;

for my $line (@lines)
{
$line =~ /TITLE/ and $title = $line;
$line =~ /AUTHOR/ and $author = $line;
$line =~ /CALL/ and $call = $line;
$line =~ /SUBJ/ and $subj = $line;
#$line =~ /did not find/ and print $title,$line,"\n";
$line =~ /PUB/ and print $title,$author,$call,$subj,$line,"\n";

}
 
R

Richard Gration

having all sorts of problems extracting the data. The file I am
extracting on is library catalog records. For instance sometimes I get
the subject printing in the wrong record, or blank lines between each
subject (some records have more than one subject field)

It looks to me like you aren't removing the newline from the end of your
input lines. See extra line in code below.

my $title;
my $author;
my $call;
my $subj;

for my $line (@lines)
{

chomp($line); # <-- Will remove newline from end of $line, if present
 
T

Tad McClellan

sometimes I get
the subject printing in the wrong record, or blank lines between each
subject

for my $line (@lines)


The problem must be in the data contained in @lines.

Since you haven't shown us how you are loading @lines, we
cannot help you with your problem.
 
P

phaylon

having all sorts of problems extracting the data. The file I am extracting
on is library catalog records. For instance sometimes I get the subject
printing in the wrong record, or blank lines between each subject (some
records have more than one subject field)

I'm sorry, but this is way to less information to work with. Could you
post some example formatted data you read in? (if @lines is just the sum
of all lines in file)


p
 
M

mjl69

having all sorts of problems extracting the data. The file I am
extracting on is library catalog records. For instance sometimes I
get the subject printing in the wrong record, or blank lines between
each subject (some records have more than one subject field)

eg: Author Joe Blow
Title Fishing in a coal mine
SUBJ Fishing
SUBJ Coal mines

I'll get results like this
Author Joe Blow
Title Fishing in a coal mine
SUBJ Fishing

SUBJ Coal mines

I'd like to be able for instance keep things together and then have a
blank line between the last element of the first record and a space
between the start of the next record: Here is the script

my $title;
my $author;
my $call;
my $subj;

for my $line (@lines)
{
$line =~ TITLE and $title = $line;
$line =~ AUTHOR and $author = $line;
$line =~ CALL and $call = $line;
$line =~ SUBJ and $subj = $line;
#$line =~ /did not find/ and print $title,$line,"\n";
$line =~ PUB and print $title,$author,$call,$subj,$line,"\n";

}

seems like a similar problem to reading e-mail headers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top