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