It is possible to populate the four arrays in one go by pushing onto the correct array as decided by nested ternaries. However, it doesn't look particularly clean and simple and you are probably better off to start with following ww's suggestion to break the problem into two stages. Here's one way to do it in one fell swoop.
knoppix@Microknoppix:~$ perl -Mstrict -wE ' > open my $fh, q{<}, \ <<EOD or die $!; > name1,a1,b1,c1 > name2,a2,b2,c2 > name3,a3,b3,c3 > EOD > > my( @c1, @c2, @c3, @c4 ); > while ( <$fh> ) > { > chomp; > my $idx = 0; > push @{ > $_->[ 0 ] == 1 ? \ @c1 > : $_->[ 0 ] == 2 ? \ @c2 > : $_->[ 0 ] == 3 ? \ @c3 > : \ @c4 }, $_->[ 1 ] for > map { [ ++ $idx, $_ ] } > split m{,}; > } > > say q{}; > say qq{@c1}; > say qq{@c2}; > say qq{@c3}; > say qq{@c4};' name1 name2 name3 a1 a2 a3 b1 b2 b3 c1 c2 c3 knoppix@Microknoppix:~$
I hope this is of interest.
Update: corrected broken link.
Cheers,
JohnGG
In reply to Re: Nested Loop Problems
by johngg
in thread Nested Loop Problems
by cuautemoc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |