1Lingua::EN::Numbers::OrUdsienratCeo(n3t)ributed Perl DocLuimnegnutaa:t:iEoNn::Numbers::Ordinate(3)
2
3
4

NAME

6       Lingua::EN::Numbers::Ordinate -- go from cardinal number (3) to ordinal
7       ("3rd")
8

SYNOPSIS

10         use Lingua::EN::Numbers::Ordinate;
11         print ordinate(4), "\n";
12          # prints 4th
13         print ordinate(-342), "\n";
14          # prints -342nd
15
16         # Example of actual use:
17         ...
18         for(my $i = 0; $i < @records; $i++) {
19           unless(is_valid($record[$i]) {
20             warn "The ", ordinate($i), " record is invalid!\n";
21             next;
22           }
23           ...
24         }
25

DESCRIPTION

27       There are two kinds of numbers in English -- cardinals (1, 2, 3...),
28       and ordinals (1st, 2nd, 3rd...).  This library provides functions for
29       giving the ordinal form of a number, given its cardinal value.
30

FUNCTIONS

32       ordinate(SCALAR)
33           Returns a string consisting of that scalar's string form, plus the
34           appropriate ordinal suffix.  Example: "ordinate(23)" returns
35           "23rd".
36
37           As a special case, "ordinate(undef)" and "ordinate("")" return
38           "0th", not "th".
39
40           This function is exported by default.
41
42       th(SCALAR)
43           Merely an alias for "ordinate", but not exported by default.
44
45       ordsuf(SCALAR)
46           Returns just the appropriate ordinal suffix for the given scalar
47           numeric value.  This is what "ordinate" uses to actually do its
48           work.  For example, ordsuf(3) is "rd".
49
50           Not exported by default.
51
52       The above functions are all prototyped to take a scalar value, so
53       "ordinate(@stuff)" is the same as "ordinate(scalar @stuff)".
54

CAVEATS

56       * Note that this library knows only about numbers, not number-words.
57       "ordinate('seven')" might just as well be "ordinate('superglue')" or
58       "ordinate("\x1E\x9A")" -- you'll get the fallthru case of the input
59       string plus "th".
60
61       * As is unavoidable, "ordinate(0256)" returns "174th" (because ordinate
62       sees the value 174). Similarly, "ordinate(1E12)" returns
63       "1000000000000th".  Returning "trillionth" would be nice, but that's an
64       awfully atypical case.
65
66       * Note that this library's algorithm (as well as the basic concept and
67       implementation of ordinal numbers) is totally language specific.
68
69       To pick a trivial example, consider that in French, 1 ordinates as
70       "1ier", whereas 41 ordinates as "41ieme".
71

STILL NOT SATISFIED?

73       Bored of this...?
74
75         use Lingua::EN::Numbers::Ordinate qw(ordinate th);
76         ...
77         print th($n), " entry processed...\n";
78         ...
79
80       Try this bit of lunacy:
81
82         {
83           my $th_object;
84           sub _th () { $th_object }
85
86           package Lingua::EN::Numbers::Ordinate::Overloader;
87           my $x; # Gotta have something to bless.
88           $th_object = bless \$x; # Define the object now, which _th returns
89           use Carp ();
90           use Lingua::EN::Numbers::Ordinate ();
91           sub overordinate {
92             Carp::croak "_th should be used only as postfix!" unless $_[2];
93             Lingua::EN::Numbers::Ordinate::ordinate($_[1]);
94           }
95           use overload '&' => \&overordinate;
96         }
97
98       Then you get to do:
99
100         print 3 & _th, "\n";
101           # prints "3rd"
102
103         print 1 + 2 & _th, "\n";
104           # prints "3rd" too!
105           # Because of the precedence of & !
106
107         print _th & 3, "\n";
108           # dies with: "th should be used only as postfix!"
109
110       Kooky, isn't it?  For more delightful deleria like this, see Damian
111       Conway's Object Oriented Perl from Manning Press.
112
113       Kinda makes you like th(3), doesn't it?
114

SEE ALSO

116       Lingua::EN::Inflect provides an "ORD" function, which returns the
117       ordinal form of a cardinal number.
118
119       Lingua::EN::Number::IsOrdinal provides an "is_ordinal" function, which
120       returns true if passed an ordinal number.
121

REPOSITORY

123       <https://github.com/neilbowers/Lingua-EN-Numbers-Ordinate>
124
126       Copyright (c) 2000 Sean M. Burke.  All rights reserved.
127
128       This library is free software; you can redistribute it and/or modify it
129       under the same terms as Perl itself.
130

AUTHOR

132       Sean M. Burke "sburke@cpan.org"
133
134
135
136perl v5.30.0                      2019-07-26  Lingua::EN::Numbers::Ordinate(3)
Impressum