in reply to Simple (probably)
For each hash element, you execute
if ($value =~ /$search/gi) { $contains++; }
$contains++ isn't in any kind of loop, so it gets executed at most once. So let's add the loop we need:
while ($value =~ /$search/gi) { $contains++; }
This is equivalent, yet simpler and faster:
++contains while $value =~ /$search/gi;
And this is faster yet (assuming $search contains no captures):
$contains += () = /$search/gi;
By the way, using m//g in scalar context outside of while condition is a bug.* This includes using it as an if condition.
* — Yes, this is a generalisation, but it's accurate for those don't know what makes the statement incomplete.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple (probably)
by MaroonBalloon (Acolyte) on Dec 13, 2009 at 05:21 UTC | |
by ikegami (Patriarch) on Dec 13, 2009 at 05:37 UTC |