On Dec 31, 2007 2:56 PM, Jean-Rene David <[EMAIL PROTECTED]> wrote:

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

This type of curiosity would be well served by studying other people's
Perl code. Find some module or program you're interested in, and see
how it was done. Or study the examples in a good book like The Perl
Cookbook.

Having said that, here are some ideas....

You could omit the array, and put your split expression directly into
the foreach.

If your data are logically a list of lines, you might keep them in an
array instead of a scalar in the first place.

If you are (in some sense) transforming the elements, you could use a
map instead of a foreach.

There are probably other useful techniques, depending upon what else
you're doing with the data.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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


Reply via email to