http://www.perlmonks.org?node_id=646465


in reply to Re: Printing an array using while loop
in thread Printing an array using while loop

In addition to using a "last" in a while loop - which is not good practice, this solution goes against the spirit of the OP's question.
  • Comment on Re^2: Printing an array using while loop

Replies are listed 'Best First'.
Re^3: Printing an array using while loop
by Not_a_Number (Prior) on Oct 22, 2007 at 19:28 UTC
    Well it made me laugh, especially as the "spirit of the OP's question" is obviously homework. :)

      (drifting off-topic...)

      It was actually useful for me, even though it's not a homework assignment :)

      I wanted to send the results to a file (not a problem), but this syntax caused a space to be inserted at the beginning of the second and subsequent lines. I'm already generating the array elements with a terminating newline, so I had to use:

      print FILE join( "", @array );

      To get what I wanted.

      Thanks though, for helping me to think outside of the looping concept.

        Why join? If you're already generating the array elements with a terminating newline, why not just:

        c:\@Work\Perl\monks>perl -wMstrict -e "my @ra = (qq{bat\n}, qq{ball\n}, qq{glove\n}); print @ra; " bat ball glove


        Give a man a fish:  <%-{-{-{-<