Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Is there a well-know equivalent of python's zip in perl?
I can write my own,
sub zip { my @A; foreach my $i (0..$#{$_[0]}) { push @A, [ map { $_->[$i] } @_ ]; } wantarray and return @A; return \@A; }
But it seems kinda clunky -- are there ready-made solutions? Also, I would like to unzip, as well as convert interleaved arrays into arrays of pairs, e.g., A1, B1, A2, B2 -pairs-> [ A1, B1, A2,B2 ]. Please tell me I simply need to RTFM!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: equivalent of python's zip in perl
by LanX (Saint) on Nov 21, 2010 at 22:24 UTC | |
by Anonymous Monk on Jan 31, 2012 at 18:30 UTC | |
|
Re: equivalent of python's zip in perl
by Corion (Patriarch) on Nov 21, 2010 at 22:26 UTC | |
|
Re: equivalent of python's zip in perl
by cdarke (Prior) on Nov 22, 2010 at 08:13 UTC | |
by moritz (Cardinal) on Nov 22, 2010 at 08:33 UTC |