in reply to Collapsing repetitive equality tests: || vs {} vs // (an observation)

You neglected to also look at the any predicate or its overworking cousin grep. Or perhaps Perl 6's any() disjunction or its (forward in history) "backport" any() from Quantum::Superpositions.

my $chr = $_; # Naughty, naughty! You used $_ before but I need it now +. any { $chr eq $_ } qw( a b c ); grep { $chr eq $_ } qw( a b c );

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

  • Comment on Re: Collapsing repetitive equality tests: || vs {} vs // (an observation)
  • Download Code

Replies are listed 'Best First'.
Re^2: Collapsing repetitive equality tests: || vs {} vs // (an observation)
by blogical (Pilgrim) on Feb 26, 2007 at 14:54 UTC

    Feel free to drop a link to a reference to any, as I have no idea what you're referring to (sadly, I'm not hip to that Perl 6 jazz). grep, however, I can dig. It does make the test a bit large though.

    On a tangent, it would be interesting to be able to ask for the value of $_ "x back" so that we could say something like grep { $_{0} eq $_{1} } qw( a b c ) or grep { $_ eq $_{1} } qw( a b c )

      any can be found in List::MoreUtils.

      I was bored a while ago, and plugged both any and grep into ikegamis benchmark script. They're slow.

        There's also any() in List::Utils.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊