Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Pluralize nouns

by turnstep (Parson)
on Dec 11, 2000 at 17:03 UTC ( [id://46069]=note: print w/replies, xml ) Need Help??


in reply to Pluralize nouns

A few notes:

  • "shift(@_)" can be written simply as "shift"
  • The subroutine should return a string, instead of setting a global variable. It's a good practice to get into, especially when you start messing with packages.
  • A return also allows the sub to be stuck directly into the program without using a variable (see the chad example below)
  • The ternary operator is cool. :)
my $plur = &pluralize($items); print "$items item$plur listed"; print "I counted $chads vote", &pluralize($chads),"!\n"; sub pluralize($) { return shift==1 ? "" : "s"; }

Log In?
Username:
Password:

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

    No recent polls found