Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by Jim (Curate)
on Jul 09, 2014 at 21:39 UTC ( #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
Node Status?
node history
Node Type: note [id://1092974]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2020-09-28 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (144 votes). Check out past polls.

    Notices?