Except my previous post is wrong. Perl hashes are so dang slick that they beat all my hackery with arrays and pseudo-hashes. In deference to those who say CPU cycles DO NOT MATTER!, the difference is small enough that the OP could chose the method that is the most readable.

#!/usr/bin/perl require 5.8.8; use strict; use fields; use Benchmark 'cmpthese'; use Hash::Util 'lock_keys'; use Data::Dumper; my @range = ('a'..'z'); # Define a perl 5.8 pseudo hash my $inputs = fields::phash(\@range, [ map { [1,1] } @range ]); $inputs->{c} = [ 0, 1 ]; $inputs->{f} = [ 2, 1 ]; $inputs->{g} = [ 0, 1 ]; my $phash = sub { map $inputs->{$_}, @range}; # Define an AofA with index conversion my @iRange = (0..25); my @array = map { [1, 1] } @iRange; my $aoa = sub { map $array[ ord($_)-97 ], @range }; # Define a hash my %HofA = map { $_=>[1, 1] } @range; my $hoa = sub { map $HofA{$_}, @range }; # Define a locked hash my %LHofA = map { $_=>[1, 1] } @range; lock_keys(%LHofA, @range); my $lhoa = sub { map $LHofA{$_}, @range }; cmpthese ( 10000, { pseudohash => $phash, Hash_of_Arrays => $hoa, Locked_Hash => $lhoa, Array_of_Arrays => $aoa, }); __END__ perl src/symarray.pl [ +8:54pm] (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) Rate pseudohash Array_of_Arrays Hash_of_Arrays L +ocked_Hash pseudohash 19104/s -- -12% -36% + -37% Array_of_Arrays 21695/s 14% -- -27% + -29% Hash_of_Arrays 29767/s 56% 37% -- + -2% Locked_Hash 30476/s 60% 40% 2% + --


s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}

In reply to Re^2: quickly create reference to boring hash. by starbolin
in thread quickly create reference to boring hash. by tford

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.