Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: printing 20 characters in a line.

by ikegami (Pope)
on Nov 14, 2008 at 06:11 UTC ( #723570=note: print w/replies, xml ) Need Help??


in reply to Re: printing 20 characters in a line.
in thread printing 20 characters in a line.

Either you don't need $cnt, or you don't need to iterate over the indexes.
for (0..$#array){ if ($_ % 20 == 19){ print OUT "$array[$_]\n"; } else{ print OUT "$array[$_] "; } }
for (@array){ if (++$cnt % 20 == 0){ print OUT "$_\n"; } else{ print OUT "$_ "; } }

It's probably worth noting the last line has a trailing space and isn't terminated.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2020-07-08 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?