Table creation/Postal addresses: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Add a Perl 6 example) |
m (→version 1: changed the wording in the boxed comments, added/changed comments and whitespace, changed indentations of the output, simplified the specification for addresses, used a template for the output.) |
||
Line 885: | Line 885: | ||
===version 1=== |
===version 1=== |
||
A REXX program can call SQL or any other database system, but the version shown here is a RYO (roll your own). |
A REXX program can call SQL or any other database system, but the version shown here is a RYO (roll your own). |
||
Practically no error checking (for invalid fields, etc.) has been coded. |
|||
⚫ | |||
for other countries. |
|||
⚫ | |||
⚫ | |||
parish, country, etc) could be added without exclusion. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
<pre> |
<pre> |
||
╔════════╤════════════════════════════════════════════════════════════════════════╤══════╗ |
|||
╔═════════════════════════════════════════════════════════════════════════════════╗ |
|||
╟────────┘ Format of an entry in the USA address/city/state/zip code structure: └──────╢ |
|||
║ ║ |
║ ║ |
||
║ The |
║ The structure name can be any variable name, but here it'll be shortened to make these║ |
||
║ |
║ comments and program easier to read; its name will be: @USA or @usa (or both).║ |
||
⚫ | |||
║ be @USA (in any letter case). In addition, the following variable names ║ |
|||
║ Each of the variable names beginning with an underscore (_) aren't to be used elsewhere║ |
|||
║ (stemmed array tails) will need to be kept uninitialized (that is, not used ║ |
|||
║ |
║ in the program. Other possibilities are to have a trailing underscore (or both) or ║ |
||
║ some other special eye─catching character such as: ! @ # $ ? ║ |
|||
║ underscore in the beginning of each name. Other possibilities are to have a ║ |
|||
⚫ | |||
║ trailing underscore (or both leading and trailing), or some other special eye─ ║ |
|||
║ Any field not specified will have a value of a null (which has a length of zero). ║ |
|||
⚫ | |||
║ ║ |
║ ║ |
||
║ Any field |
║ Any field may contain any number of characters, this can be limited by the ║ |
||
║ |
║ restrictions imposed by the standards or the USA legal definitions. ║ |
||
║ Any |
║ Any number of fields could be added (with testing for invalid fields). ║ |
||
╟────────────────────────────────────────────────────────────────────────────────────────╢ |
|||
║ restrictions imposed by the standards or the USA legal definitions. ║ |
|||
║ |
║ @USA.0 the number of entries in the @USA stemmed array. ║ |
||
⚫ | |||
╟─────────────────────────────────────────────────────────────────────────────────╢ |
|||
║ |
║ nnn is some positive integer of any length (no leading zeros). ║ |
||
╟────────────────────────────────────────────────────────────────────────────────────────╢ |
|||
⚫ | |||
║ |
║ @USA.nnn._name is the name of person, business, or a lot description. ║ |
||
╟────────────────────────────────────────────────────────────────────────────────────────╢ |
|||
╟─────────────────────────────────────────────────────────────────────────────────╢ |
|||
║ @USA.nnn. |
║ @USA.nnn._addr1 is the 1st street address ║ |
||
║ @USA.nnn._addr2 is the 2nd street address ║ |
|||
╟─────────────────────────────────────────────────────────────────────────────────╢ |
|||
║ @USA.nnn. |
║ @USA.nnn._addr3 is the 3rd street address ║ |
||
║ @USA.nnn. |
║ @USA.nnn._addrNN ··· (any number, but in sequential order). ║ |
||
╟────────────────────────────────────────────────────────────────────────────────────────╢ |
|||
⚫ | |||
║ @USA.nnn. |
║ @USA.nnn._state is the USA postal code for the state, territory, etc. ║ |
||
╟────────────────────────────────────────────────────────────────────────────────────────╢ |
|||
╟─────────────────────────────────────────────────────────────────────────────────╢ |
|||
║ @USA.nnn. |
║ @USA.nnn._city is the official city name, it may include any character. ║ |
||
╟────────────────────────────────────────────────────────────────────────────────────────╢ |
|||
╟─────────────────────────────────────────────────────────────────────────────────╢ |
|||
║ @USA.nnn. |
║ @USA.nnn._zip is the USA postal zip code (five or ten digit format). ║ |
||
╟────────────────────────────────────────────────────────────────────────────────────────╢ |
|||
╟─────────────────────────────────────────────────────────────────────────────────╢ |
|||
║ @USA.nnn. |
║ @USA.nnn._upHist is the update history: userID who did the update; date, timestamp.║ |
||
╚════════════════════════════════════════════════════════════════════════════════════════╝ |
|||
╟─────────────────────────────────────────────────────────────────────────────────╢ |
|||
║ @USA.nnn._upHist is the update history (who, date, and timestamp). ║ |
|||
╚═════════════════════════════════════════════════════════════════════════════════╝ |
|||
</pre> |
</pre> |
||
<lang rexx>/*REXX program creates, builds, and displays a table of given U.S.A. postal addresses.*/ |
<lang rexx>/*REXX program creates, builds, and displays a table of given U.S.A. postal addresses.*/ |
||
@usa.=; @usa.0=0 |
@usa.=; @usa.0=0; $='@USA.' /*initialize array and first value.*/ |
||
@usa.0=@usa.0+1 /*bump the unique number for usage. |
@usa.0=@usa.0 + 1 /*bump the unique number for usage.*/ |
||
call USA '_city' , 'Boston' |
call USA '_city' , 'Boston' |
||
call USA '_state' , 'MA' |
call USA '_state' , 'MA' |
||
call USA ' |
call USA '_addr1' , "51 Franklin Street" |
||
call USA '_name' , "FSF Inc." |
call USA '_name' , "FSF Inc." |
||
call USA '_zip' , '02110-1301' |
call USA '_zip' , '02110-1301' |
||
@usa.0=@usa.0+1 /*bump the unique number for usage. |
@usa.0=@usa.0 + 1 /*bump the unique number for usage.*/ |
||
call USA '_city' , 'Washington' |
call USA '_city' , 'Washington' |
||
call USA '_state' , 'DC' |
call USA '_state' , 'DC' |
||
call USA ' |
call USA '_addr1' , "The Oval Office" |
||
call USA '_addr2' , "1600 Pennsylvania Avenue NW" |
call USA '_addr2' , "1600 Pennsylvania Avenue NW" |
||
call USA '_name' , "The White House" |
call USA '_name' , "The White House" |
||
call USA '_zip' , 20500 |
call USA '_zip' , 20500 /*no need for quotes for a number. */ |
||
call USA 'list' |
call USA 'list' |
||
exit |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
⚫ | |||
⚫ | |||
call tell '_addr' |
|||
⚫ | |||
call tell '_city' |
|||
call tell '_state' |
|||
call tell '_zip' |
|||
say copies('─', 40) |
|||
return |
return |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
⚫ | |||
⚫ | |||
if ?=='LIST' then do #=1 for @usa.0 |
|||
⚫ | |||
⚫ | |||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
⚫ | |||
call tell '_city' |
|||
call tell '_state' |
|||
call tell '_zip' |
|||
say copies('─', 45) |
|||
end /*#*/ |
|||
else do; call value $ || @usa.0'.'what , arg(2) |
|||
return</lang> |
|||
call value $ || @usa.0'.upHist' , userid() date() time() |
|||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
<pre> |
<pre> |
||
name ──► FSF Inc. |
name ──► FSF Inc. |
||
addr1 ──► 51 Franklin Street |
|||
city ──► Boston |
city ──► Boston |
||
state ──► MA |
|||
zip ──► 02110-1301 |
zip ──► 02110-1301 |
||
───────────────────────────────────────────── |
|||
──────────────────────────────────────── |
|||
name ──► The White House |
name ──► The White House |
||
addr1 ──► The Oval Office |
|||
addr2 ──► 1600 Pennsylvania Avenue NW |
|||
city ──► Washington |
city ──► Washington |
||
state ──► DC |
|||
zip ──► 20500 |
zip ──► 20500 |
||
───────────────────────────────────────────── |
|||
──────────────────────────────────────── |
|||
</pre> |
</pre> |
||