User:Rich Farmbrough/perl snippets

Month comparison
sub monthcmp{ my $a=lc(@_[0]); my $b=lc(@_[1]); my $c=335503014; my @a = unpack("CCC", $a); my @b = unpack("CCC", $b); $a = (@a[0]-97)*676 + (@a[1]-97)*26 +(@a[2]-97); $b = (@b[0]-97)*676 + (@b[1]-97)*26 +(@b[2]-97);

$a=$a*$a%$c; $a=$a*$a%$c; $a=$a*$a%$c; $a=$a*$a%$c; $a=$a*$a%$c; $a=$a*$a%$c;

$b=$b*$b%$c; $b=$b*$b%$c; $b=$b*$b%$c; $b=$b*$b%$c; $b=$b*$b%$c; $b=$b*$b%$c;

return ($a<=>$b); }