in reply to Re: Re: returning data from a for() loop?
in thread returning data from a for() loop?

I would use split...
my @chars = split(//, $string);
When you call split with an empty pattern "//", it automatically splits into individual characters and returns that list of characters.

To print the results out as you have, then do this...

print join("\n", split(//, $string)), "\n";
The split() works as I stated above.
The join takes each element of the list it is given in the second arguement and puts the first arguement after it, forming a string; Exception, then last item in the list does not get the first arguement appended to it -- that is why I added the last "\n".

Replies are listed 'Best First'.
Re4: returning data from a for() loop?
by strfry() (Monk) on Jun 08, 2001 at 23:33 UTC
    ah! thank you! i hadn't quite understood fully how those worked, just some simple ways to use them (which i didn't like); and yes that not only works, its way easier to read, too! (:

    strfry()