sub any (&$@) { my $code = shift; local $A = shift; local $B = shift; while ((local $a=pop(@$A)) && (local $b=pop(@$B)) ) { return 1 if &$code($a,$b); } return 0; } sub all(&$@) { my $code = shift; local $A = shift; local $B = shift; while ((local $a=pop(@$A)) && (local $b=pop(@$B)) ) { return 0 unless &$code($a,$b); } return 1; } # Some testing: my @ar1 = 1..10; my @ar2 = 2..11; my $res= any { $a<$b } \@ar1, \@ar2; print "res=$res ==1?\n"; $res= any { $a>$b } \@ar1, \@ar2; print "res=$res ==0?\n"; $res= any { $a==$b } \@ar1, \@ar2; print "res=$res ==0?\n"; @ar2=1..10; $res= all { $a==$b } \@ar1, \@ar2; print "res=$res ==1?\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Quantum::Superpositions (was RE: any-all)
by merlyn (Sage) on Sep 02, 2000 at 08:55 UTC | |
by davorg (Chancellor) on Sep 02, 2000 at 20:38 UTC | |
by merlyn (Sage) on Sep 02, 2000 at 20:59 UTC | |
|
RE: any-all
by Adam (Vicar) on Sep 02, 2000 at 02:07 UTC | |
by fundflow (Chaplain) on Sep 02, 2000 at 02:13 UTC | |
by Adam (Vicar) on Sep 02, 2000 at 02:21 UTC | |
by fundflow (Chaplain) on Sep 02, 2000 at 02:31 UTC | |
by Adam (Vicar) on Sep 02, 2000 at 03:15 UTC |