Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: printing unequal sized lists side by side

by wind (Priest)
on May 28, 2011 at 05:46 UTC ( [id://907103]=note: print w/replies, xml ) Need Help??


in reply to printing unequal sized lists side by side

Using a basic loop and List::Util. Most of the additional code is there for simple formatting.

use List::Util qw(max); use warnings; use strict; my @array1 = (1..5, 10); my @array2 = ('a'..'h'); my $length = max map {length} @array1; for my $i (0..max($#array1, $#array2)) { printf "% ${length}s %s\n", $array1[$i] // '', $array2[$i] // ''; } __END__ 1 a 2 b 3 c 4 d 5 e 10 f g h

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2024-03-28 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found