NAME

Tie::Plural - Select a string variant based on a quantity.

VERSION

This documentation describes version 0.01 of Plural.pm, January 07, 2005.

SYNOPSIS

$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);

DESCRIPTION

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.

VARIABLES

%pl
$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.

Only $number is required. $plural_form defaults to 's'. $singular_form defaults to '' (the empty string). $zero_form defaults to whatever $plural_form is.

FUNCTIONS

plural
$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.

This function is not exported by default.

EXAMPLES

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."

EXPORTS

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.

SEE ALSO

Damian Conway's excellent Lingua::EN::Inflect provides a much more full-featured way to produce plural forms automagically.

AUTHOR / COPYRIGHT

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.