in reply to read 2 array simultaneously
And in the spirit of TIMTOWTDI, the Perl6 inspired ...
sub zip { my ($ref1, $ref2) = @_; my @zip; while (@$ref1 || @$ref2) { push @zip => shift @$ref1 || undef; push @zip => shift @$ref2 || undef; } return @zip; } my $x = 1; my $y = 2; my @a=qw(1 2 3); my @b=qw(7 8 9); my @zip = zip(\@a, \@b); while (my ($item, $element) = splice @zip => 0, 2) { print "$x: $item $y: $element\n"; }
Better written as:
for zip(@a,@b) -> $item, $element { say "$x: $item $y: $element"; }
But you'll have to wait a bit for that syntax to work :)
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: read 2 array simultaneously
by thor (Priest) on Jan 12, 2005 at 04:13 UTC | |
by Ovid (Cardinal) on Jan 12, 2005 at 04:56 UTC |