Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 about the Monastery: (15)
As of 2014-12-18 18:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (59 votes), past polls