Skip to content

Instantly share code, notes, and snippets.

@spiculator
Created February 11, 2012 06:34
Show Gist options
  • Save spiculator/1797308 to your computer and use it in GitHub Desktop.
Save spiculator/1797308 to your computer and use it in GitHub Desktop.
getmul
#!/usr/bin/perl
use warnings;
use strict;
sub getmul($$$$) {
my $num = shift;
my $num2 = $num % 100;
my $last = $num2 % 10;
my $case = $num2 > 4 && $num2 < 21 ? 2 :
1 == $last ? 0 :
$last > 1 && $last < 5 ? 1
: 2;
return sprintf "%d %s", $num, $_[$case];
}
printf "%s\n", getmul 122, "услуга", "услуги", "услуг";
printf "%s\n", getmul 38, "попугай", "попугая", "попугаев";
printf "%s\n", getmul 33, "год", "года", "лет";
printf "%s\n", getmul 1001, "ночь", "ночи", "ночей";
__END__
sergey@athlon:/tmp$ ./mul.pl
122 услуги
38 попугаев
33 года
1001 ночь
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment