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

(dooberwah) Re: Printing an array in columns - improvements?

by dooberwah (Pilgrim)
on Jul 18, 2002 at 15:32 UTC ( [id://182860]=note: print w/replies, xml ) Need Help??


in reply to Printing an array in columns - improvements?

Here's my attempt at the same problem.

#!/usr/local/bin/perl -w use strict; use POSIX; my @array = qw/one two three four five six seven eight nine ten/; my $cols = 3; my $tabs = 1; foreach my $value ( @array ) { my $foo = ceil( length( $value ) / 8 ); $tabs = $foo if $tabs < $foo; } while ( @array ) { for ( 1 .. $cols ) { my $slice = shift @array; print $slice if defined $slice; print "\t" for 1 .. $tabs; } print "\n"; }

-Ben Jacobs

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-18 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found