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

I do not believe that "for"s return a result.

Are you trying to split the string into individual characters? Then you should read up on "split".
Are you trying to manipulate each element of an array and hold onto the manipulation? Then you should read up on "map".

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