This could be extended to deal with greater that Ninety-Nine Hundred Ninety-Ninth Street if needed:) Probably has bugs and limitations, but then what doesn't.

#! perl -slw use strict; my $re_road = qr[(?: street | avenue | road | way )]xi; my $re_11 = qr[(?: first | second | third | fourth | fifth | sixth | seventh | eight | nineth )]xi; my $re_12 = qr[(?: tenth | eleventh | twelveth | thirteenth | fourt +eenth | fiveteenth | sixteenth | seventeenth | eighteenth | nineteenth + )]xi; my $re_21 = qr[(?: one | two | three | four | five | six | seven | eight | nine | ten )]xi; my $re_22 = qr[(?: tenth | eleven | twelve | thirteen | fourteen | +fiveteen | sixteen | seventeen | eighteen | nineteen )]xi; my $re_23 = qr[(?: twenty | thirty | fourty | fifty | sixty | seventy | eighty | ninety )]xi; my $re_3 = qr[(?: hundred | thousand )]xi; my $re_all = qr[ (?: (?: ($re_23) [\s-]+ )? ($re_21) [\s-]+ ($re_3) \s+ )? (?: (?: (?: (?: ($re_23) [\s-]+ )? ($re_11) ) | ($re_12) ) ) \s+ $re_road ]xi; my %teens = ( one=>1, two=>2, three=>3, four=>4, five=>5, six=>6, seven=>7, eight=>8, nine=>9, ten=>10, eleven=>11, twelve=>12, thirteen=>13, fourteen=>14, fiveteen=>15, sixteen=>16, seventeen=>17, eighteen=>18, nineteen=>19, ); my %teenths = ( first=>1, second=>2, third=>3, fourth=>4, fifth=>5, sixth=>6, seventh=>7, eigth=>8, nineth=>9, tenth=>10, eleventh=>11, twelfth=>12, thirteenth=>13, fourteenth=>14, fifteen +th=>15, sixteenth=>16, seventeenth=>17, eighteenth=>18, nineteenth=>19, ); my %orties = ( twenty=>20, thirty=>30, fourty=>40, fifty=>50, sixty=>60, seventy=>70, eighty=>80, ninety=>90, ); my %mags = ( hundred=>1e2, thousand=>1e3, million=>1e6, ); my @bits; while( <DATA> ) { @bits = grep{$_} @bits if @bits = $_ =~ m[$re_all]; my $n=0; for( @bits ) { $n += $orties{$_} if exists $orties{$_}; $n += $teens{$_} if exists $teens{$_}; $n *= $mags{$_} if exists $mags{$_}; $n += $teenths{$_} if exists $teenths{$_}; } $n .= ( 'th', qw[st nd rd], ('th')x6 )[substr($n,-1)]; print join '|', @bits, " => $n"; } __DATA__ third street fourth avenue nineteenth street twenty-fifth way fifty-first street one hundred twenty third street three hundred thirty third street thirty-three hundred seventy-fifth street

Output

D:\Perl\test>261018 third| => 3rd fourth| => 4th nineteenth| => 19th twenty|fifth| => 25th fifty|first| => 51st one|hundred|twenty|third| => 123rd three|hundred|thirty|third| => 333rd thirty|three|hundred|seventy|fifth| => 3375th

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

In reply to Re: Address conversion by BrowserUk
in thread Address conversion by tcf22

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.