http://qs321.pair.com?node_id=254993


in reply to Help to slurp records - $/ maybe?

You could use the following (coarse, not fully tested, yada yada yada) approach:
#!/usr/bin/perl -w use strict; use warnings; my $data; { local $/ = undef; $data = <DATA>; } print "Record: [$1]\n" while ( $data =~ /(Field 1:.*?Field 3:[^\n]+)/sg ); __DATA__ Field 1: abc Field 2: asdasdasdf Field 2: asdsaads Field 2: asdf Field 3: asfssadfsad Field 1: abc Field 2: asdf Field 3: asfssadfsad Field 1: abc
Which outputs:
Record: [Field 1: abc Field 2: asdasdasdf Field 2: asdsaads Field 2: asdf Field 3: asfssadfsad] Record: [Field 1: abc Field 2: asdf Field 3: asfssadfsad] Record: [Field 1: abc Field 2: asdasdasdf2 Field 2: asdf3 Field 3: asfssadfsad]

HTH,

-- JaWi

"A chicken is an egg's way of producing more eggs."

Replies are listed 'Best First'.
Re: Re: Help to slurp records - $/ maybe?
by Limbic~Region (Chancellor) on May 02, 2003 at 13:55 UTC
    JaWi,
    Thanks - I already know that trick. The problem is it isn't scalable. The larger the file is that you are slurping the more memory you need to have. I am processing logs that are in the vincinity of a gigabyte and have millions of records.

    Cheers - L~R

      In that case I would go for the "flag option" which isn't such memory consuming as slurping in the whole file.
      Interesting problem though...

      HTH,

      -- JaWi

      "A chicken is an egg's way of producing more eggs."