On 08/09/2006 11:15 AM, Octavian Rasnita wrote:
Hi,

I have a program that contains a pretty big block of text:

my $text = <<EOF;
line1
line2
...
line 120000
EOF

I want to read this block of text line by line and analyse each line without
needing to create a big array that contains all these lines (exactly like
when reading line by line from a text file).

It works fine if the program contains just a block of text, because in that
case I can put the data after __DATA__ and then use while(<DATA>), but the
program contains 2 blocks of text.

Is there a solution for this?


There are two solutions I can think of. You can open an "in memory" variable (see perldoc -f open), e.g.

  open (FH, '<', \$text) or die(....);

Or you can use the /m and /g options of the match operator to match lines within the big text string (see perldoc perlop), e.g.

  while ($text =~ m/^.*$/mg) {
    print "Current line = $&\n";
  }

Thank you.

Octavian



You're welcome.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to