in reply to Capturing Multiple lined data with regex.

I'm not so sure you should be doing all of the work inside of a regular expression. Here are two ways to do what you're after:

Example #1

open(my $fh, "<", $ARGV[0]) or die "\n$0 Error => $^E\n"; my $data = do { local $/; <$fh> }; close $fh; my @records = split /(?=\n\d+\s+)/, $data; # Now each item of @records has the lines you're looking for
Example #2
open(my $fh, "<", $ARGV[0]) or die "\n$0 Error => $^E\n"; my (@records,$rec); while (<$fh>) { unless (/^\d+\s+/) { $rec .= $_; next } push @records, $rec if $rec; $rec = $_ } push @records, $rec if $rec; close $fh; # Now each item of @records has the lines you're looking for

Can you guess which example I like best? :-)

You can use various print statements if you don't want to populate an array of course.

Replies are listed 'Best First'.
Re^2: Capturing Multiple lined data with regex.
by blackadder (Hermit) on Dec 08, 2004 at 22:00 UTC
    Kool stuff,...Thanks a lot.

    But let me guess, Example #1. right?

    :-)
    Blackadder