in reply to grep value in hash

Try this
@ary = grep{/one/} values %hash; print "found", if(scalar @ary > 0);

Replies are listed 'Best First'.
Re^2: grep value in hash
by davorg (Chancellor) on Feb 20, 2006 at 12:58 UTC

    I can't see how scalar @art could ever return a negative number, so your >0 check is probably overkill.

    print "found" if scalar @ary;

    But, given that grep in scalar contents returns the number of matches, I'd probably skip the temporary value and use:

    print "found" if grep { /one/ } values %hash;

    Oh, and using a regex to match a fixed string is inefficient.

    print "found" if grep { $_ eq 'one' } values %hash;

    And we're pretty much back to my first solution :)

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg