Hi, I was just refactoring some code and saw a possible opportunity to use this advice. But. Instead of having multiple strings in
@strings to process, I leave all the lines from my file joined together as one giant string with embedded
\n chars. From this angle, since I only have to use each regex once across all the strings via them being 'joined' into one string, I won't benefit from
qr.
my ( $crummy, $good );
foreach my $crummy_good_ar ( @corrections_to_make ) {
( $crummy, $good ) = @$crummy_good_ar;
$file_in_string_form =~ s/\b(\Q$crummy\E)\b/$good/ig;
}
However, as you can see (?) from the example above, I have lots of
crummy/good switchouts to do, and is my plodding approach above the best that can be expected?
P.S. Can you clarify/update what you meant by:
the benefit of qr// objects is lost if there is additional text in the pattern match
I think you are saying that a precompiled/qr regex used in a follow-on regex will have to be recompiled if you snap additional text on to the qr'd variable, because the overall text of the new regex will be different. Although at least one would still have the benefit of 'concentrated regex logic' within the qr'd variable?