Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > stop extra lines from printing

Reply
Thread Tools

stop extra lines from printing

 
 
pauliecat@sasktel.net
Guest
Posts: n/a
 
      02-02-2005
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";

}

 
Reply With Quote
 
 
 
 
Richard Gration
Guest
Posts: n/a
 
      02-02-2005
On Wed, 02 Feb 2005 01:49:31 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> 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.

<SNIP>

> my $title;
> my $author;
> my $call;
> my $subj;
>
> for my $line (@lines)
> {


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

> $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";
>
> }


 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      02-02-2005
(E-Mail Removed) <(E-Mail Removed)> wrote:

> 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.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
phaylon
Guest
Posts: n/a
 
      02-02-2005
(E-Mail Removed) wrote:

> 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

--
http://www.dunkelheit.at/
Thru the darkness of futures past, the magician longs to see.
One chants out between two worlds: Fire, walk with me.
-- Twin Peaks, »Bob«

 
Reply With Quote
 
mjl69
Guest
Posts: n/a
 
      02-02-2005
(E-Mail Removed) wrote:

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does return-by-value mean extra copies and extra overhead? mathieu C++ 3 09-04-2009 04:25 PM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:28 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-18-2007 10:11 AM
How to break the lines in printing to html lines? Ciba LO Perl Misc 4 07-08-2006 02:58 AM
How to eliminate the extra 0's in printing to html lines? cibalo@gmx.co.uk Perl Misc 7 07-05-2006 01:31 AM



Advertisments