Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: substitution with regex

by Athanasius (Archbishop)
on Jan 23, 2018 at 06:46 UTC ( [id://1207730]=note: print w/replies, xml ) Need Help??


in reply to Re^2: substitution with regex
in thread substitution with regex

Hello drose2211,

The sprintf function applies the formatting specified in the template supplied as its first argument, to produce a string using the remaining arguments. In this case, the template ' %d/%d ' means: print a space, followed by the next argument formatted as an integer, followed by a slash, followed by the next argument formatted as an integer, followed by a space. Without the sprintf function, the code would be longer and less elegant:

$line =~ s{ \s (M?\d{2}) / (M?\d{2}) \s } { ' ' . int(convert($1)) . '/' . int(convert($2)) . ' ' }xeg +;

(Perl’s printf and sprintf functions are derived from their equivalents in C. In Perl, there is also print, which does not take a template, but there is no corresponding sprint.)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-24 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found