Hash from two arrays: Difference between revisions

m
→‎{{header|REXX}}: allowed multiple hash keys to point to a particular value.
m (→‎{{header|REXX}}: added whitespace and changed comments, used a template for the output section..)
m (→‎{{header|REXX}}: allowed multiple hash keys to point to a particular value.)
Line 1,466:
 
=={{header|REXX}}==
This REXX version allows multiple keys for a value,   the keys are case sensitive.
<lang rexx>/*REXX program demonstrates hashing of a stemmed array (from a key). or multiple keys)*/
key.= /*names of the nine regular polygons. */
vals= 'triangle quadrilateral pentagon hexagon heptagon octagon nonagon decagon dodecagon'
keyskey.1= 'thuhree vour phive sicks zeaven ate nein den duzun'
key.2='three four five six seven eight nine ten /* [↑] blanks added to humorous keys */twelve'
callkey.3='3 hash vals,keys 4 5 6 /*hash the keys7 to the values. 8 9 10 */12'
key.4='III IV V VI VII VIII IX X XII'
key.5='iii iv v vi vii viii ix x xii'
hash.='───(not defined)───' /* [↑] blanks added to humorous keys */
/* just because it looks prettier.*/
do k=1 while key.k\==''
call hash vals,keys /*hash the keys to the values. */
call hash vals,key.k /*hash the keys to the values. */
end /*k*/
 
parse arg query . /*obtain what was specified on the C.L.*/
if query=='' then exit /*Nothing? Then leave Dodge City. */
pad=say 'key:' left(''query, 3040) "value:" hash.query /*useddisplay forsome paddingstuff to the displayterminal. */
say 'key:' query pad "value:" hash.query /*display some stuff to the terminal. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
hash: procedure expose hash.; parse arg v,k@val,hash.@key
do j=1 untilfor map==''words(@key); map= word(k@key, j)
hash.map= word(v@val, j)
end /*j*/
return</lang>
{{out|output|text=&nbsp; when using the default input value of: &nbsp; &nbsp; <tt> phive </tt>}}
<pre>
key: phive value: pentagon
</pre>
{{out|output|text=&nbsp; when using the input value of: &nbsp; &nbsp; <tt> dingsta </tt>}}
<pre>
key: dingsta value: ───(not defined)───
</pre>