in reply to Converting a stringified regexp back into a regexp
For efficiency purposes, you might want to keep the non-stringified regexp inside the hash. In other words, changing:
$hash{"$regexp"} = $value; ... $value = $hash{$key}; $regexp = qx/$key/; # Expensive
to
$hash{"$regexp"} = [ $regexp, $value ]; ... $value = $hash{$key}[1]; $regexp = $hash{$key}[0];
That way, you won't have to recompile the regexp.
OR! If you can't change the hash's structure, keep the compiled regexp in a second hash:
$hash{"$regexp"} = $value; $regexps{"$regexp"} = $regexp; ... $value = $hash{$key}; $regexp = $regexps{$key};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Converting a stringified regexp back into a regexp
by tlm (Prior) on Apr 07, 2005 at 14:52 UTC | |
|
Re^2: Converting a stringified regexp back into a regexp
by mirod (Canon) on Apr 07, 2005 at 14:51 UTC |