in reply to Re^2: Trouble grepping values when hash contains multiple values per key
in thread Trouble grepping values when hash contains multiple values per key

Is there any way to force grep to evaluate these in a scalar context in order to return a "true" or "false" in this case?

Yes, evaluate grep in scalar context. It's that easy!

my $found_any = grep { ... } @whatever;

Boolean context is also a scalar context.

  • Comment on Re^3: Trouble grepping values when hash contains multiple values per key
  • Download Code

Replies are listed 'Best First'.
Re^4: Trouble grepping values when hash contains multiple values per key
by eyepopslikeamosquito (Archbishop) on Jun 06, 2010 at 03:13 UTC

    my $found_any = grep { ... } @whatever;
    Because grep always iterates through the entire list, to stop on the first one found, you might try instead:
    use List::MoreUtils qw(any); my $found_any = any { ... } @whatever;
    or:
    use List::Util qw(first); my $found_any = defined first { ... } @whatever;
    ...though, in practice, it is unlikely to matter, performance-wise, unless @whatever is huge.

    As an aside, note that both any and first are built in to Perl 6.