Apropos of the annonuced inflection module on this list. I recently
created a function for that. But my intention was primarely to make the
usage of it easy, with as few chars as possible.
This is my version, intended for numbers only. For usege in TT, just
export it as a var; $tt->process($tempalte, { inflect => \&inflect })
=head2 inflect
inflect( $number, $one, $many )
inflect( $number, $none, $one, $many )
If called without $none, it will use $many for $none.
Replaces %d with the $number.
Uses $many for negative numbers
=head3 example
inflect( 1, "no things", "a thing", "%d things")
returns "a thing"
inflect(0, "a thing", "%d things")
returns "0 things"
=cut
sub inflect # inflection = böjning
{
my( $number, $none, $one, $many ) = @_;
# Support calling with or without the $none option
if( $many )
{
# If called with %d, interpolate the number
$many =~ s/\%d/$number/;
}
else
{
$many = $one;
# If called with %d, interpolate the number
$many =~ s/\%d/$number/;
$one = $none;
$none = $many;
}
if( $number == 0 )
{
return $none;
}
elsif( $number == 1 )
{
return $one;
}
else
{
# Also for negative numbers
return $many;
}
}
--
/ Jonas - http://jonas.liljegren.org/myself/
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates