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

Re: Passing multiple arrays to foreach loop

by Random_Walk (Prior)
on May 11, 2013 at 07:48 UTC ( #1033085=note: print w/replies, xml ) Need Help??


in reply to Passing multiple arrays to foreach loop

This will work and you will itterate a list containing each element from each array. If you should want to be able to tell which array is which then you can itterate references instead.

use strict; use warnings; my @foo = qw(one two three); my @bar = qw(four five six); my @baz = qw(seven eight nine); my $i = 0; for my $array_ref (\@foo, \@bar, \@baz) { # pass references print "starting array: ".++$i."\n"; for (@$array_ref) { # de-reference print " array: $i val: $_\n"; } }

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033085]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2018-05-23 21:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?