Revision 0975a120
Von Sven Schöling vor fast 16 Jahren hinzugefügt
bin/mozilla/common.pl | ||
---|---|---|
580 | 580 |
$lxdebug->leave_sub(); |
581 | 581 |
} |
582 | 582 |
|
583 |
sub cross(&\@\@) { |
|
584 |
my $op = shift; |
|
585 |
use vars qw/@A @B/; |
|
586 |
local (*A, *B) = @_; # syms for caller's input arrays |
|
587 |
|
|
588 |
# Localise $a, $b |
|
589 |
my ($caller_a, $caller_b) = do |
|
590 |
{ |
|
591 |
my $pkg = caller(); |
|
592 |
no strict 'refs'; |
|
593 |
\*{$pkg.'::a'}, \*{$pkg.'::b'}; |
|
594 |
}; |
|
595 |
|
|
596 |
my $limit = $#A > $#B? $#A : $#B; # loop iteration limit |
|
597 |
|
|
598 |
local(*$caller_a, *$caller_b); |
|
599 |
|
|
600 |
# This map expression is also the return value. |
|
601 |
map { my $b_index = $_; |
|
602 |
map { my $a_index = $_; |
|
603 |
# assign to $a, $b as refs to caller's array elements |
|
604 |
(*$caller_a, *$caller_b) = \($A[$a_index], $B[$b_index]); |
|
605 |
$op->(); # perform the transformation |
|
606 |
} 0 .. $#A; |
|
607 |
} 0 .. $#B; |
|
608 |
} |
|
609 |
|
|
583 | 610 |
1; |
Auch abrufbar als: Unified diff
Kreuzprodukt aus zwei Arrays in List::MoreUtils Stil.
usage:
@crossed_array = cross { func($a, $b) } @array1, @array2;