in reply to Re^2: a simple question...
in thread a simple question...

@matches would contain the keys of the hash that matched. If all you care about are the values, then use this construct:
if (my @values = grep {$_} @input{qw(info1 info2 info3)}) { print "Matched values: @values"; } else { print "none of the conditions were met\n"; }
But then again, you could continue to match keys, and use a slice to access the values inside the if. It all depends on what your needs are.
if (my @matches = grep {$input{$_}} qw(info1 info2 info3)) { print "Matched keys: @matches"; print "Matched values: @input{@matches}"; } else { print "none of the conditions were met\n"; }
- Miller

Replies are listed 'Best First'.
Re^4: a simple question...
by Nkuvu (Priest) on Nov 28, 2007 at 18:07 UTC

    Is there any way to terminate the grep upon a successful match? Not that I think it matters for only three elements, more out of curiosity (and lack of much experience with grep).

      Yes. Use the List::Util first function.
      use List::Util qw(first); if (my $match = first {$input{$_}} qw(info1 info2 info3)) { print "First Matched key: $match"; print "First Matched value: $input{$match}"; } else { print "none of the conditions were met\n"; }
      - Miller