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

Re: sprintf("%ss", ...)

by Jim (Curate)
on Jul 09, 2014 at 21:39 UTC ( [id://1092974]=note: print w/replies, xml ) Need Help??


in reply to sprintf("%ss", ...)

Here's one way:

my $message = sprintf('%d %s been loaded', $v, $v == 1 ? 'volume h +as' : 'volumes have')

Here's a demonstration:

C:\>perl -E "say sprintf('%d %s been loaded', $_, $_ == 1 ? 'volume ha +s' : 'volumes have') for 0 .. 9" 0 volumes have been loaded 1 volume has been loaded 2 volumes have been loaded 3 volumes have been loaded 4 volumes have been loaded 5 volumes have been loaded 6 volumes have been loaded 7 volumes have been loaded 8 volumes have been loaded 9 volumes have been loaded C:\>

Alternatively (simpler):

my $message = sprintf 'Volumes loaded: %d', $v;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-25 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found