Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!perl # This program massages the driving directions (in USA) for plain tex +t # printing (preferably in monospace font, w/ a blank line between eac +h non # empty line), with these priorities (in no particular order) ... # - up-case road names, exit numbers, places # - low-case everything else # - expand n, w, e, s to north, west, east, south # - shorten road type (like mailing address), e.g. 'road' to 'rd', ' +lane' to # 'ln', etc. # - removes the annoying 'go' from 'go <this much>' use warnings; use strict; my ( $geo_pos , $roads ) = ( get_geo_pos() , get_road() ); my @relative_pos = map uc( $_ ) , qw(left middle center right) ; # Got a better name for this variable? my $less_important_than_roads_places = qr{ \b ( bear | stay | head | continue | follow | go | take | turn | entry | ramp | (?: to | fore? )w[oa]rds? | on.?to | on | to | for | at | off? | then | t?here | from | an?d? | (?: h(?:ou)?r | min(?:ute)? | second | moment )s? | ph(?:one)? | fax | e.?mail | home | office | work | cell | mo +bile ) \b }xi; my $misc_edits = { 'and' => '&' , 'hour' => 'hr' , 'minutes?' => 'min' , 'seconds' => 'second' , 'phone' => 'ph' , 'fore?w[oa]rd' => 'forward' , 'toword' => 'toward' } ; { local $^I = '' ; while ( <> ) { s{ \s+ the \s+ }/ /xig; s{ \b go (?: \s+ for )? \s+ (\d) }/ $1/xige; $_ = uc $_; s{ (\d) \W* ( mi(?:le)? | ft) \b }/"$1~" . lc $2/xige; s{ $less_important_than_roads_places }/lc $1/xige; for my $map ( $roads , $geo_pos , $misc_edits ) { while ( my ( $k , $v ) = each %$map ) { s[ \b $k \b ]/$v/xig; } } for my $r ( values %$roads ) { s/\b $r \./$r/xig; } s/^[ \t]+//g; s/[ \t]+$//g; s/[ \t]+/ /g; print; } } sub get_geo_pos { my @points = qw( east west north south north-east north-west south-east south-west east-north east-south west-north west-south ) ; my %points ; foreach ( @points ) { m{^ ([a-z])[a-z]+ (?: \W+ ( [a-z])[a-z]+ )? $}xi; $points{ $2 ? "$1$2" : $1 } = uc $_ ; } return { %points }; } sub get_road { my %roads = ( 'avenue' => 'ave' , 'av' => 'ave' , 'circle' => 'crl' , 'court' => 'ct' , 'crt' => 'ct' , 'drive' => 'dr' , 'lane' => 'ln' , 'pk' => 'pike' , 'parkway' => 'pkwy' , 'pky' => 'pkwy' , 'road' => 'rd' , 'route' => 'rt' , 'street' => 'st' , 'tpk' => 'turnpike' , 'turn.?pk' => 'turnpike' ); $_ = uc $_ for values %roads; return { %roads }; }

In reply to Massage the driving directions (in USA) by parv

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-19 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found