Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: tcl like 1 loop with two operators

by Mask (Pilgrim)
on Jan 25, 2011 at 15:14 UTC ( #884137=note: print w/ replies, xml ) Need Help??


in reply to Re: tcl like 1 loop with two operators
in thread tcl like 1 loop with two operators

Or in case if arrays with $i and $j values are predefined, I would write it like that:

my @i=(1,2); my @j=(3,4); my @a = map {[$i[$_],$j[$_]]} 0..$#i; foreach my $ij (@a){ my ($i, $j) = @{$ij}; say $i; say $j; }
OR if it's necessary to emulate TCL behaviour for different lengths of arrays with $i and $j values, I would write it like that:
my @i=(1,2); my @j=(3,4,5); my @len = sort(scalar(@i),scalar(@j)); my @a = map {[$i[$_],$j[$_]]} 0..$len[-1]; foreach my $ij (@a){ my ($i, $j) = @{$ij}; print $i."\n"; print $j."\n"; }


Comment on Re^2: tcl like 1 loop with two operators
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2015-07-06 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls