Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How do I Loop over multiple arrays simultaneously ?

by Fox (Pilgrim)
on Feb 25, 2010 at 16:56 UTC ( [id://825341]=note: print w/replies, xml ) Need Help??


in reply to How do I Loop over multiple arrays simultaneously ?

And the answer from RosettaCode:

sub zip (&@) { my $code = shift; my $min; $min = $min && $#$_ > $min ? $min : $#$_ for @_; for my $i ( 0 .. $min ) { $code->( map $_->[$i] , @_ ); } } my @a1 = qw( a b c ); my @a2 = qw( A B C ); my @a3 = qw( 1 2 3 ); zip { print @_,"\n" } \( @a1, @a2, @a3 );

This implementation will stop producing items when the shortest array ends.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found