in reply to Grep fail condition

In general

So applying this to you little code snippet:

for my $k (sort keys %$hFiles) { # ^$k$ forces $k to match the entire value of each entry in @aFiles # - ^ forces match at start of entry # - $ forces match at end of entry # - ^$k$ expands to whatever is in $k, # i.e. $k="x", then expands to ^x$ # # next if scalar grep... will go back to start of loop whenever one # or more values match # - scalar grep - returns number of matches # - next goes back to start of loop next if scalar grep( /^$k$/, @aFiles); print "key=$k\n"; }

For more information, see scalar and perlre

Best, beth

Replies are listed 'Best First'.
Re^2: Grep fail condition
by chromatic (Archbishop) on Nov 08, 2010 at 16:57 UTC
    next if scalar grep( /^$k$/, @aFiles);

    if already imposes scalar context on its operand.