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

i'm trying to split them into individual characters with an arbitrary character inbetween each one (in this case, either "\n" or <br>
i did try to read up on map, but i need simpler explanations/examples than i found... so would it be split or map?

strfry()

Replies are listed 'Best First'.
Re: Re: Re: returning data from a for() loop?
by Sifmole (Chaplain) on Jun 08, 2001 at 23:24 UTC
    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".
      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()