Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: formatting zipcodes

by Kanji (Parson)
on Apr 14, 2002 at 22:14 UTC ( [id://159026]=note: print w/replies, xml ) Need Help??


in reply to formatting zipcodes

See (s)printf, which can be coerced into right-padding with zeros (instead of spaces) if the string is shorter than a desired length...

my $zip = sprintf "%05d", 9876;

    --k.


Replies are listed 'Best First'.
Re: Re: formatting zipcodes
by mumphis (Initiate) on Apr 14, 2002 at 22:30 UTC
    perfect, thanks(all) for the quick reply
      If you are writing this code for international use remember that not all postal codes are five digits. The post codes in Australia, for example, are 4 digits long.
        ...and in Canada, it's letter-number-letter number-letter-number.
        _______________
        D a m n D i r t y A p e
        Home Node | Email
        Not wanting to re-state the obvious I will make this short. I have the joy of working with both US and Canadian Addresses (maybe Mexico soon) and the best solution is to just format them as strings as stated below (and above i believe) with double quotes. This gets around all the stupid thinks like spaces, letters and US postal zip codes (5-4 format).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://159026]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2024-04-18 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found