Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Help to slurp records - $/ maybe?

by JaWi (Hermit)
on May 02, 2003 at 13:52 UTC ( [id://254993]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://254993]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-26 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found