![]() |
|
Think about Loose Coupling | |
PerlMonks |
Re: Using sprintf in regular expreession.by rsFalse (Chaplain) |
on Feb 02, 2022 at 20:12 UTC ( #11141080=note: print w/replies, xml ) | Need Help?? |
s/PATTERN/REPLACEMENT/msixpodualngcer: >> e Evaluate the right side as an expression. The whole right side of the regex is evaluated. You can't make some parts of the REPLACEMENT evaluated and some not. So you should wrap "$3-" and "-$2" in doublequotes and join all parts by concatenation, e.g.: $date =~ s/(\d+)-(\d+)-(\d+)/ "$3-" . sprintf("%02d",$1) . "-$2" /ge; Upd. You need double quotes to interpolate $3 and $2 (single quotes won't).
In Section
Seekers of Perl Wisdom
|
|