From: "Rob Dixon" <[EMAIL PROTECTED]> > > 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? > > In Perl 5.8 and onwards you can read directly from the string as if it were a > file by just opening with a scalar reference instead of a filname. That seems to > be exactly what you want. >
Thank you very much for your suggestion. It works, but unfortunately very very slow. If I put the data after __DATA__ and read <DATA>, it works very fast, but if I create a $text var that holds the same data then open(DATA, "<", \$text), it works more than 100 times slower. Here is what I have done: open(IN, "<", \$text) or die - $!; while(<IN>) { if (/$ARGV[0]/) { my ($word, $word2) = split '##', $_, 2; print "$word = $word2\n"; last; } } print times(); Am I doing something wrong, or can I do something to improve the speed? Thank you. Teddy -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>