Chris Stinemetz wrote:

I would like to only work with the data that has a line with |68| in it
print that line and then print each subsequent lines in that match
/\|7\|\d+\|\d+/ until #END is reached and then repeat for the rest of the
input data.

Below is what I have attempted.

Thanks in advance.

Chris


#!/usr/bin/perl

use warnings;
use strict;

my ( $col1, $col2, $col3 );

while( my $line =<DATA>  ) {
chomp($line);
if ( $line =~ /(.*\|68\|.*)/ ) {
my $OM = $1;
print $OM, "\n";
}
  if ( $line =~ /(\|\d)\|(\d+)\|(\d+)/ ) {
$col1 = $1;
$col2 = $2;
$col3 = $3;
print join("\t", $col1, $col2, $col3 ), "\n";
}
}

Let's re-factor that down to its essence:

while ( <DATA> ) {
    print if /\|68\|/;
    print "$1\t$2\t$3\n" if /(\|\d)\|(\d+)\|(\d+)/;
    }

Now we need to add something that starts at |68| and stops at #END:

while ( <DATA> ) {
    if ( /\|68\|/ .. /^#END/ ) {
        print if /\|68\|/;
        print "$1\t$2\t$3\n" if /(\|\d)\|(\d+)\|(\d+)/;
        }
    }



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to