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

Re: Pluralize nouns

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.