Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Using sprintf in regular expreession.

by LanX (Saint)
on Feb 02, 2022 at 23:58 UTC ( [id://11141092]=note: print w/replies, xml ) Need Help??


in reply to Re: Using sprintf in regular expreession.
in thread Using sprintf in regular expreession.

> Perhaps a bit more long winded

IMHO, you are overcomplicating it. sprintf can take a list of values, no need for a map.

It can even rearrange the order, tho I prefer the slice here.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re^2: Using sprintf in regular expreession.

Replies are listed 'Best First'.
Re^3: Using sprintf in regular expreession.
by LanX (Saint) on Feb 03, 2022 at 10:52 UTC
    TIMTOWTDI

    DB<23> $date = "3-15-1932" #### split and slice DB<24> printf "% 4d-%02d-%02d", (split /-/, $date)[2,0,1] 1932-03-15 #### match list DB<25> printf "% 4d-%02d-%02d", ($date =~ /(\d+)-(\d+)-(\d+)/ )[2,0, +1] 1932-03-15 #### reorder printf with 3$ DB<26> printf "%3\$ 4d-%02d-%02d", split /-/, $date 1932-03-15 #### classic DB<27> printf "% 4d-%02d-%02d",$3,$1,$2 if $date =~ /(\d+)-(\d+)-(\d ++)/ 1932-03-15

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11141092]
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-25 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found