P is for Practical | |
PerlMonks |
Re: Text switching (updated)by AnomalousMonk (Archbishop) |
on Sep 14, 2022 at 05:22 UTC ( [id://11146872]=note: print w/replies, xml ) | Need Help?? |
my $digits_4 = qr{ (?<!-)\b[0-9]{4}\b(?!-) }xms; $digits_4 =~ /$unitslist/ seems to be matching the stringization of Regexp (regex or qr//) object $digits_4 to a string $unitslist of all possible unit numbers (assuming $unitslist is the same as $unitslist_4) that has been compiled as a match regex. I don't understand the purpose of this. unless ($digits_4 =~ /$unitslist/) { ... } is doing the match described above and executing a conditional block (which contains the substitution) if there is no match. I don't understand this either. A simple approach to the general problem would be to uniquely mark all unit number sub-strings: %1234% or {{1234}}. This would also allow for easy support of unit numbers like 123A or 12-B or C-4 or even Penthouse! Substitution matching then becomes straightforward and unambiguous. Update: A spelling correction, and a few minor wording changes for clarity. Give a man a fish: <%-{-{-{-<
In Section
Seekers of Perl Wisdom
|
|