Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Printing an array using while loop

by Anonymous Monk
on Oct 23, 2007 at 15:38 UTC ( #646702=note: print w/replies, xml ) Need Help??


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

(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.

Replies are listed 'Best First'.
Re^5: Printing an array using while loop
by AnomalousMonk (Bishop) on May 19, 2020 at 23:06 UTC

    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:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2020-08-13 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (75 votes). Check out past polls.

    Notices?