Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Welcome to the Monastery
 
PerlMonks  

Re: can we pass two variable to foreach loop

by ferreira (Chaplain)
on Mar 28, 2007 at 10:18 UTC ( #606964=note: print w/ replies, xml ) Need Help??


in reply to can we pass two variable to foreach loop

Adding to the suggestions by BrowserUk, Zaxo and grinder, another possible solution would be to use each_array from List::MoreUtils. It is a bit of overkill for your current case, but it would work well if you generalized your problem to:

foreach my ($x,$y) (@name,@lastname) { do something }
Only that it would be written as:
use List::MoreUtils qw(each_array); ... my $names = each_array(@name, @lastname); while ( my ($x, $y) = $names->() ) { do something }
With each_array, you may create an iterator which is able to loop over more than one array at once. That easy.


Comment on Re: can we pass two variable to foreach loop
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-04-20 18:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (486 votes), past polls