Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Printing an array using while loop

by Anonymous Monk
on Oct 22, 2007 at 05:52 UTC ( #646365=note: print w/replies, xml ) Need Help??

in reply to Printing an array using while loop

while (1) { print "@array", "\n"; last; }

Replies are listed 'Best First'.
Re^2: Printing an array using while loop
by perlfan (Priest) on Oct 22, 2007 at 15:18 UTC
    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.
      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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://646365]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2020-08-15 12:53 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (78 votes). Check out past polls.