Jean-Rene David wrote:
Hi,

I wonder what idioms are available to loop through
the lines stored in a scalar variable. I guess I'm
looking for something analogous to these idioms
for files and arrays respectively:

while(<FH>) {
# do stuff
}

foreach (@array) {
# do stuff
}

When I had to do this I split the scalar in an
array:

@array = split "\n", $scalar;
foreach (@array) {
# do stuff
}

What would be some other ways to do this? (This is
purely curiosity.)

I suggest:

while ($str =~ /(.*?\n|.+\z)/g) {
  my $line = $1;
    :
    :
}

Rob

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


Reply via email to