stop extra lines from printing

Discussion in 'Perl Misc' started by pauliecat@sasktel.net, Feb 2, 2005.

  1. Guest

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

    }
     
    , Feb 2, 2005
    #1
    1. Advertising

  2. On Wed, 02 Feb 2005 01:49:31 -0800, 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";
    >
    > }
     
    Richard Gration, Feb 2, 2005
    #2
    1. Advertising

  3. <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 2, 2005
    #3
  4. phaylon Guest

    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«
     
    phaylon, Feb 2, 2005
    #4
  5. mjl69 Guest

    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.
     
    mjl69, Feb 2, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Taylor
    Replies:
    2
    Views:
    1,102
    Eric J. Roode
    Aug 4, 2003
  2. Chris Bedford
    Replies:
    1
    Views:
    676
    Ben Edgington
    May 21, 2004
  3. mathieu
    Replies:
    3
    Views:
    602
    Bo Persson
    Sep 4, 2009
  4. Replies:
    7
    Views:
    119
    Joe Smith
    Jul 5, 2006
  5. Ciba LO
    Replies:
    4
    Views:
    188
    Ciba LO
    Jul 8, 2006
Loading...

Share This Page