Lingua-EN-Numbers-Ordinate-1.02/0000755000177300017730000000000010164725732017160 5ustar sburkesburke00000000000000Lingua-EN-Numbers-Ordinate-1.02/META.yml0000644000177300017730000000052010164725732020426 0ustar sburkesburke00000000000000# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Lingua-EN-Numbers-Ordinate version: 1.02 version_from: lib/Lingua/EN/Numbers/Ordinate.pm installdirs: site requires: distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17 Lingua-EN-Numbers-Ordinate-1.02/t/0000755000177300017730000000000010164725732017423 5ustar sburkesburke00000000000000Lingua-EN-Numbers-Ordinate-1.02/t/01_old_junk.t0000644000177300017730000000070310164675241021714 0ustar sburkesburke00000000000000 # Time-stamp: "2004-12-29 18:48:49 AST" use strict; use Test; BEGIN { plan tests => 14 }; use Lingua::EN::Numbers::Ordinate; ok 1; ok ordinate(3), '3rd'; ok ordinate(-3), '-3rd'; ok ordinate(13), '13th'; ok ordinate(33), '33rd'; ok ordinate(-513), '-513th'; ok ordinate(1), '1st'; ok ordinate(2), '2nd'; ok ordinate(4), '4th'; ok ordinate(5), '5th'; ok ordinate(0), '0th'; ok ordinate(''), '0th'; ok ordinate(undef), '0th'; ok ordinate(22), '22nd'; Lingua-EN-Numbers-Ordinate-1.02/t/00_about_verbose.t0000644000177300017730000000423010164714052022736 0ustar sburkesburke00000000000000 require 5; # Time-stamp: "2004-12-29 20:54:50 AST" # Summary of, well, things. use Test; BEGIN {plan tests => 2}; ok 1; use Lingua::EN::Numbers::Ordinate (); #chdir "t" if -e "t"; { my @out; push @out, "\n\nPerl v", defined($^V) ? sprintf('%vd', $^V) : $], " under $^O ", (defined(&Win32::BuildNumber) and defined &Win32::BuildNumber()) ? ("(Win32::BuildNumber ", &Win32::BuildNumber(), ")") : (), (defined $MacPerl::Version) ? ("(MacPerl version $MacPerl::Version)") : (), "\n" ; # Ugly code to walk the symbol tables: my %v; my @stack = (''); # start out in %:: my $this; my $count = 0; my $pref; while(@stack) { $this = shift @stack; die "Too many packages?" if ++$count > 1000; next if exists $v{$this}; next if $this eq 'main'; # %main:: is %:: #print "Peeking at $this => ${$this . '::VERSION'}\n"; if(defined ${$this . '::VERSION'} ) { $v{$this} = ${$this . '::VERSION'} } elsif( defined *{$this . '::ISA'} or defined &{$this . '::import'} or ($this ne '' and grep defined *{$_}{'CODE'}, values %{$this . "::"}) # If it has an ISA, an import, or any subs... ) { # It's a class/module with no version. $v{$this} = undef; } else { # It's probably an unpopulated package. ## $v{$this} = '...'; } $pref = length($this) ? "$this\::" : ''; push @stack, map m/^(.+)::$/ ? "$pref$1" : (), keys %{$this . '::'}; #print "Stack: @stack\n"; } push @out, " Modules in memory:\n"; delete @v{'', '[none]'}; foreach my $p (sort {lc($a) cmp lc($b)} keys %v) { $indent = ' ' x (2 + ($p =~ tr/:/:/)); push @out, ' ', $indent, $p, defined($v{$p}) ? " v$v{$p};\n" : ";\n"; } push @out, sprintf "[at %s (local) / %s (GMT)]\n", scalar(gmtime), scalar(localtime); my $x = join '', @out; $x =~ s/^/#/mg; print $x; } print "# Running", (chr(65) eq 'A') ? " in an ASCII world.\n" : " in a non-ASCII world.\n", "#\n", ; print "# \@INC:\n", map("# [$_]\n", @INC), "#\n#\n"; print "# \%INC:\n"; foreach my $x (sort {lc($a) cmp lc($b)} keys %INC) { print "# [$x] = [", $INC{$x} || '', "]\n"; } ok 1; Lingua-EN-Numbers-Ordinate-1.02/MANIFEST0000644000177300017730000000031210164725724020306 0ustar sburkesburke00000000000000ChangeLog lib/Lingua/EN/Numbers/Ordinate.pm Makefile.PL MANIFEST MANIFEST.SKIP README t/00_about_verbose.t t/01_old_junk.t META.yml Module meta-data (added by MakeMaker) Lingua-EN-Numbers-Ordinate-1.02/ChangeLog0000644000177300017730000000050110164677262020732 0ustar sburkesburke00000000000000Revision history for Perl extension Lingua::EN::Numbers::Ordinate Time-stamp: "2004-12-29 19:06:10 AST" 2004-12-29 Sean M. Burke sburke@cpan.org * Release 1.02 -- no code changes, just rebundling 2000-08-24 Sean M. Burke sburke@cpan.org * Release 0.01 -- first release Lingua-EN-Numbers-Ordinate-1.02/MANIFEST.SKIP0000644000177300017730000000006510164677321021057 0ustar sburkesburke00000000000000^MANIFEST\.bak$ Makefile(\.old)?$ \.rej$ CVS blib ~ Lingua-EN-Numbers-Ordinate-1.02/lib/0000755000177300017730000000000010164725732017726 5ustar sburkesburke00000000000000Lingua-EN-Numbers-Ordinate-1.02/lib/Lingua/0000755000177300017730000000000010164725732021145 5ustar sburkesburke00000000000000Lingua-EN-Numbers-Ordinate-1.02/lib/Lingua/EN/0000755000177300017730000000000010164725732021447 5ustar sburkesburke00000000000000Lingua-EN-Numbers-Ordinate-1.02/lib/Lingua/EN/Numbers/0000755000177300017730000000000010164725732023062 5ustar sburkesburke00000000000000Lingua-EN-Numbers-Ordinate-1.02/lib/Lingua/EN/Numbers/Ordinate.pm0000644000177300017730000001056710164677275025206 0ustar sburkesburke00000000000000 require 5; package Lingua::EN::Numbers::Ordinate; use strict; # Time-stamp: "2004-12-29 19:06:20 AST" use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); require Exporter; @ISA = ('Exporter'); @EXPORT = ('ordinate'); @EXPORT_OK = ('ordsuf', 'th'); $VERSION = "1.02"; ########################################################################### =head1 NAME Lingua::EN::Numbers::Ordinate -- go from cardinal number (3) to ordinal ("3rd") =head1 SYNOPSIS use Lingua::EN::Numbers::Ordinate; print ordinate(4), "\n"; # prints 4th print ordinate(-342), "\n"; # prints -342nd # Example of actual use: ... for(my $i = 0; $i < @records; $i++) { unless(is_valid($record[$i]) { warn "The ", ordinate($i), " record is invalid!\n"; next; } ... } =head1 DESCRIPTION There are two kinds of numbers in English -- cardinals (1, 2, 3...), and ordinals (1st, 2nd, 3rd...). This library provides functions for giving the ordinal form of a number, given its cardinal value. =head1 FUNCTIONS =over =item ordinate(SCALAR) Returns a string consisting of that scalar's string form, plus the appropriate ordinal suffix. Example: C returns "23rd". As a special case, C and C return "0th", not "th". This function is exported by default. =item th(SCALAR) Merely an alias for C, but not exported by default. =item ordsuf(SCALAR) Returns just the appropriate ordinal suffix for the given scalar numeric value. This is what C uses to actually do its work. For example, C is "rd". Not exported by default. =back The above functions are all prototyped to take a scalar value, so C is the same as C. =head1 CAVEATS * Note that this library knows only about numbers, not number-words. C might just as well be C or C -- you'll get the fallthru case of the input string plus "th". * As is unavoidable, C returns "174th" (because ordinate sees the value 174). Similarly, C returns "1000000000000th". Returning "trillionth" would be nice, but that's an awfully atypical case. * Note that this library's algorithm (as well as the basic concept and implementation of ordinal numbers) is totally language specific. To pick a trivial example, consider that in French, 1 ordinates as "1ier", whereas 41 ordinates as "41ieme". =head1 STILL NOT SATISFIED? Bored of this...? use Lingua::EN::Numbers::Ordinate qw(ordinate th); ... print th($n), " entry processed...\n"; ... Try this bit of lunacy: { my $th_object; sub _th () { $th_object } package Lingua::EN::Numbers::Ordinate::Overloader; my $x; # Gotta have something to bless. $th_object = bless \$x; # Define the object now, which _th returns use Carp (); use Lingua::EN::Numbers::Ordinate (); sub overordinate { Carp::croak "_th should be used only as postfix!" unless $_[2]; Lingua::EN::Numbers::Ordinate::ordinate($_[1]); } use overload '&' => \&overordinate; } Then you get to do: print 3 & _th, "\n"; # prints "3rd" print 1 + 2 & _th, "\n"; # prints "3rd" too! # Because of the precedence of & ! print _th & 3, "\n"; # dies with: "th should be used only as postfix!" Kooky, isn't it? For more delightful deleria like this, see Damian Conway's I from Manning Press. Kinda makes you like C, doesn't it? =head1 COPYRIGHT Copyright (c) 2000 Sean M. Burke. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Sean M. Burke C =cut ########################################################################### sub ordsuf ($) { return 'th' if not(defined($_[0])) or not( 0 + $_[0] ); # 'th' for undef, 0, or anything non-number. my $n = abs($_[0]); # Throw away the sign. return 'th' unless $n == int($n); # Best possible, I guess. $n %= 100; return 'th' if $n == 11 or $n == 12 or $n == 13; $n %= 10; return 'st' if $n == 1; return 'nd' if $n == 2; return 'rd' if $n == 3; return 'th'; } sub ordinate ($) { my $i = $_[0] || 0; return $i . ordsuf($i); } *th = \&ordinate; # correctly copies the prototype, too. ########################################################################### 1; __END__ Lingua-EN-Numbers-Ordinate-1.02/Makefile.PL0000644000177300017730000000103610164707771021135 0ustar sburkesburke00000000000000# This -*-perl-*- script writes the Makefile for installing this distribution. # # See "perldoc perlmodinstall" or "perldoc ExtUtils::MakeMaker" for # info on how to control how the installation goes. # # Time-stamp: "2004-12-29 20:19:53 AST" require 5.004; use strict; use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'Lingua::EN::Numbers::Ordinate', 'VERSION_FROM' => 'lib/Lingua/EN/Numbers/Ordinate.pm', # finds $VERSION 'dist' => { COMPRESS => 'gzip -6f', SUFFIX => 'gz', }, ); Lingua-EN-Numbers-Ordinate-1.02/README0000644000177300017730000001230507151324312020030 0ustar sburkesburke00000000000000README for Lingua::EN::Numbers::Ordinate Time-stamp: "2000-08-24 16:59:23 MDT" Lingua::EN::Numbers::Ordinate [Partially excerpted from the POD.] Lingua::EN::Numbers::Ordinate -- go from cardinal number (3) to ordinal ("3rd") SYNOPSIS use Lingua::EN::Numbers::Ordinate; print ordinate(4), "\n"; # prints 4th print ordinate(-342), "\n"; # prints -342nd # Example of actual use: ... for(my $i = 0; $i < @records; $i++) { unless(is_valid($record[$i]) { warn "The ", ordinate($i), " record is invalid!\n"; next; } ... } DESCRIPTION There are two kinds of numbers in English -- cardinals (1, 2, 3...), and ordinals (1st, 2nd, 3rd...). This library provides functions for giving the ordinal form of a number, given its cardinal value. FUNCTIONS ordinate(SCALAR) Returns a string consisting of that scalar's string form, plus the appropriate ordinal suffix. Example: ordinate(23) returns "23rd". As a special case, ordinate(undef) and ordinate("") return "0th", not "th". This function is exported by default. th(SCALAR) Merely an alias for ordinate, but not exported by default. ordsuf(SCALAR) Returns just the appropriate ordinal suffix for the given scalar numeric value. This is what ordinate uses to actually do its work. For example, ordsuf(3) is "rd". Not exported by default. The above functions are all prototyped to take a scalar value, so ordinate(@stuff) is the same as ordinate(scalar @stuff). CAVEATS * Note that this library knows only about numbers, not number-words. ordinate('seven') might just as well be ordinate('superglue') or ordinate("\x1E\x9A") -- you'll get the fallthru case of the input string plus "th". * As is unavoidable, ordinate(0256) returns "174th" (because ordinate sees the value 174). Similarly, ordinate(1E12) returns "1000000000000th". Returning "trillionth" would be nice, but that's an awfully atypical case. * Note that this library's algorithm (as well as the basic concept and implementation of ordinal numbers) is totally language specific. To pick a trivial example, consider that in French, 1 ordinates as "1ier", whereas 41 ordinates as "41ieme". STILL NOT SATISFIED? Bored of this...? use Lingua::EN::Numbers::Ordinate qw(ordinate th); ... print th($n), " entry processed...\n"; ... Try this bit of lunacy: { my $th_object; sub _th () { $th_object } package Lingua::EN::Numbers::Ordinate::Overloader; my $x; # Gotta have something to bless. $th_object = bless \$x; # Define the object now, which _th returns use Carp (); use Lingua::EN::Numbers::Ordinate (); sub overordinate { Carp::croak "_th should be used only as postfix!" unless $_[2]; Lingua::EN::Numbers::Ordinate::ordinate($_[1]); } use overload '&' => \&overordinate; } Then you get to do: print 3 & _th, "\n"; # prints "3rd" print 1 + 2 & _th, "\n"; # prints "3rd" too! # Because of the precedence of & ! print _th & 3, "\n"; # dies with: "th should be used only as postfix!" Kooky, isn't it? For more delightful deleria like this, see Damian Conway's Object Oriented Perl from Manning Press. Kinda makes you like th(3), doesn't it? COPYRIGHT Copyright (c) 2000 Sean M. Burke. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AUTHOR Sean M. Burke sburke@cpan.org [End of POD excerpt] PREREQUISITES This suite requires Perl 5; I've only used it under Perl 5.004, so for anything lower, you're on your own. Lingua::EN::Numbers::Ordinate doesn't use any nonstandard modules. INSTALLATION You install Lingua::EN::Numbers::Ordinate, as you would install any perl module library, by running these commands: perl Makefile.PL make make test make install If you want to install a private copy of Lingua::EN::Numbers::Ordinate in your home directory, then you should try to produce the initial Makefile with something like this command: perl Makefile.PL LIB=~/perl DOCUMENTATION POD-format documentation is included in Ordinate.pm. POD is readable with the 'perldoc' utility. See ChangeLog for recent changes. MACPERL INSTALLATION NOTES You needn't bother with the makefiles. Just make a Lingua directory in your MacPerl site_lib or lib directory, an EN directory under that, and a Numbers directory under that, and move Ordinate.pm into there. SUPPORT Questions, bug reports, useful code bits, and suggestions for Lingua::EN::Numbers::Ordinate should just be sent to me at sburke@cpan.org AVAILABILITY The latest version of Lingua::EN::Numbers::Ordinate is available from the Comprehensive Perl Archive Network (CPAN). Visit to find a CPAN site near you.