Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Using sprintf in regular expreession.

by rsFalse (Chaplain)
on Feb 02, 2022 at 20:12 UTC ( [id://11141080]=note: print w/replies, xml ) Need Help??


in reply to Using sprintf in regular expreession.

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).

Replies are listed 'Best First'.
Re^2: Using sprintf in regular expreession.
by BillKSmith (Monsignor) on Feb 03, 2022 at 15:12 UTC
    Great explanation! See jwkrahn (above) for a simpler form of the required expression.
    Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11141080]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-24 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found