in reply to any-all

This is interesting, but beware... you are abusing sort's magic $a and $b variables. Even strict wouldn't complain, but you could have problems if the $code includes a sort.

Also don't use local there, use my. Its faster, and there is no reason to use local in this scenario.

Replies are listed 'Best First'.
RE: RE: any-all
by fundflow (Chaplain) on Sep 02, 2000 at 02:13 UTC
    Hmm.

    I'll add 'local' declaration to it.

    Thers little chance that someone will use sort there but who knows?
      Its worse then that... your tests do the same amount of abuse. Have you considered doing this with a closure?
      sub getAnyAll { my $code = shift; my $Any = sub { my @A = @{$_[0]}; # I like to dereference early, it makes my @B = @{$_[1]}; # the rest of the code more readable. while( @A and @B ) { return 1 if &$code( pop(@A), pop(@B) ) } return 0 }; my $All = sub { my @A = @{$_[0]}; my @B = @{$_[1]}; while( @A and @B ) { return 0 unless &$code( pop(@A), pop(@B) ) } return 1 }; return ( $Any, $All ); }
      that's untested, but gives you the idea. By the way... poping arrays passed by reference might not be such a good idea either...
        1. What is a closure?

        2. Writing $a is nicer (=shorter and more readable) than $_[0]

        3. I'd like to iterate through both arrays, something like
        "for $a=(@A), $b=(@B)" and thus the pop. Hopefuly perl just pops a pointer array to the original.

        The goal is a short and compact sub that will do the above.