Tie::Plural - Select a string variant based on a quantity.
This documentation describes version 0.01 of Plural.pm, January 07, 2005.
$var = $pl{$num}; $var = $pl{$num, $plural}; $var = $pl{$num, $plural, $singular}; $var = $pl{$num, $plural, $singular, $zero}; $var = plural($num); $var = plural($num, $plural); $var = plural($num, $plural, $singular); $var = plural($num, $plural, $singular, $zero);
This module provides a simple way to pluralize words within strings. More precisely, it provides a way to select a string from a number of choices based on a quantity. This is accomplished by a tied hash, so it is very easy to incorporate these choices into output strings, which is generally where you need them.
$variant = $pl{$number, $plural_form, $singular_form, $zero_form};
Based on $number, returns one of $plural_form, $singular_form, or $zero_form. If $number is 0, $zero_form is returned. If $number is 1, $singular_form is returned. Otherwise, $plural_form is returned.
$number
$plural_form
$singular_form
$zero_form
Only $number is required. $plural_form defaults to 's'. $singular_form defaults to '' (the empty string). $zero_form defaults to whatever $plural_form is.
$variant = plural($number, $plural_form, $singular_form, $zero_form);
Based on $number, returns one of the other arguments. Works the same as the %pl tied-hash does.
%pl
This function is not exported by default.
for $num (0..3) { print "I have $num dog$pl{$num}.\n"; } # The above prints: I have 0 dogs. I have 1 dog. I have 2 dogs. I have 3 dogs. $num = 700; print "My wife owns $pl{$num,'many','one','no'} dress$pl{$num,'es'}."; # "My wife owns many dresses."
The variable %pl is exported by default. The function plural is available for export. The tag :all will export all available symbols into your namespace.
plural
:all
Damian Conway's excellent Lingua::EN::Inflect provides a much more full-featured way to produce plural forms automagically.
Eric J. Roode, roode@cpan.org
Copyright (c) 2005 by Eric J. Roode. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Tie::Plural, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Plural
CPAN shell
perl -MCPAN -e shell install Tie::Plural
For more information on module installation, please visit the detailed CPAN module installation guide.