<div><font class="Apple-style-span" color="#333333" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div><div class="gmail_quote">2010/8/11 Horace Dynamite <span dir="ltr"><<a href="mailto:horace.dynamite@gmail.com">horace.dynamite@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"># And now the the thing I can't figure out how to do, the programmer<br>
creates a 2d hash, retaining the "values" column.<br>
%CODE = ( A => { map { $CODE_CHARS{A}[$_] => $_ } 0..106 },<br>
B => { map { $CODE_CHARS{B}[$_] => $_ } 0..106 },<br>
C => { map { $CODE_CHARS{C}[$_] => $_ } 0..106 } );<br></blockquote><div><br></div><div><br></div><div>Are you asking how to retain the index (i.e. the $_, what you called "values") along with the encodings? The amount of Perl code you showed did not do that (it just retains $_ without the encoding). </div>
<div><br></div><div>Assuming you want to retain both the encoding and value "together", a <b>cons</b> will do: </div><div><br></div></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;">
<div><div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace">(define (.. lower higher) ;; shorthand for perl's N..M generator syntax </font></div></div></div></div><div>
<div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace"> (build-list (- (+ higher 1) lower) (lambda (n) (+ n lower))))</font></div></div></div></div><div><div class="gmail_quote">
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div></div></div><div><div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace">(define A</font></div>
</div></div></div><div><div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace"> (make-hash (map (lambda (value) </font></div></div></div></div><div><div class="gmail_quote">
<div><div><font class="Apple-style-span" face="'courier new', monospace"> (cons (list-ref 128-A value) ;; key </font></div></div></div></div><div><div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace"> ;; encoding + value </font></div>
</div></div></div><div><div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace"> <b>(cons (list-ref ENCODING n) value)</b>))</font></div></div></div>
</div><div><div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace"> (.. 0 106))))</font></div></div><div><font class="Apple-style-span" face="'courier new', monospace">;; (define B ...) </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">;; (define C ...) </font></div></div></div></blockquote><div><div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div></div><div><br></div><div>Then you just refer to the values... </div><div><br></div></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div class="gmail_quote">
<div><font class="Apple-style-span" face="'courier new', monospace">(define (encoding-ref hash key) </font></div></div></div><div><div class="gmail_quote"><div><font class="Apple-style-span" face="'courier new', monospace"> (<b>car</b> (hash-ref hash key))) </font></div>
</div></div><div><div class="gmail_quote"><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div></div></div><div><div class="gmail_quote"><div><font class="Apple-style-span" face="'courier new', monospace">(define (value-ref hash key) </font></div>
</div></div><div><div class="gmail_quote"><div><font class="Apple-style-span" face="'courier new', monospace"> (<b>cdr</b> (hash-ref hash key))) </font></div></div></div></blockquote><div><div class="gmail_quote">
<div><br></div><div>Then you have </div><div><br></div></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace">> (encoding-ref A #\G)</font></div>
</div></div></div><div><div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace">11010001000</font></div></div></div></div><div><div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace">> (value-ref A #\G)</font></div>
</div></div></div><div><div class="gmail_quote"><div><div><font class="Apple-style-span" face="'courier new', monospace">39</font></div></div></div></div></blockquote><div><div class="gmail_quote"><div><div><br></div>
<div>Hope this is what you are looking for. </div><div><br></div><div>Cheers,</div><div>yc</div><div><br></div><div> </div></div></div>
</div>