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

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).

Replies are listed 'Best First'.
Re^5: a simple question...
by wind (Priest) on Nov 28, 2007 at 18:18 UTC
    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