I have a hash of hashes and I want to list the inner hashes $names in the order they've been entered into the hash. I know I can't use "keys" but I use keys to get the number of items with the following two lines of code ...

@myArea = sort (keys %{$camArray{$trafficArea}}); $items = scalar @myArea;

Then, I can use a "for" loop to print out each name ...

for ($i=0; $i < $items; $i++) { print "\t<option>$myArea[$i]\n"; }

but this of course uses the keys sort. So I've been trying to do something along the lines of ...

for ($j=0; $j < $items; $j++) { print "$camArray{$trafficArea}{$j}\n"; }

to get at the values in order, all to no avail. Is there a way to get at the entries in a hash in order? Here is the hash of hashes I'm using ...

%camArray = ( 'seattle' => { ' Select a Traffic Cam' => '', 'I-5 at NE 45th St' => 'cctv135', 'I-5 at Roanoke St' => 'cctv126', 'I-5 at Yesler Way' => 'cctv105', 'I-5/I-90 Interchange' => 'cctv812', 'I-5 at Holgate St' => 'cctv098', 'I-5 at Spokane St' => 'cctv093', 'I-5 at Albro Place' => 'cctv086', 'I-5 at Mid Boeing Field' => 'cctv081', 'I-90 at 18th Ave. S.' => 'cctv821', 'I-90 Midspan' => 'cctv859', 'Hwy 520 at Montlake' => 'cctv504', 'Hwy 520 Midspan' => 'cctv509', 'Hwy 99 at Michigan St' => 'cctv498', 'Hwy 99 at W Marginal Way' => 'cctv497' }, 'tacoma' => { ' Select a Traffic Cam' => '', 'Narrows Bridge - westside' => '016cc0085', 'Narrows Bridge - eastside' => '016cc0047', 'I-5 south of Tacoma' => 'TacSouth', 'I-5 north of Tacoma' => 'TacNorth', 'I-5/Hwy 16 Interchange' => '005cc1324', 'I-5 at S. 48th Street' => '005cc1312', 'Hwy 16 at Center St.' => '016cc0019', 'Hwy 16 at Pearl St.' => '016cc0037' }, );

Thanks for any help!

rHOnDO


In reply to Accessing a hash of hashes in order ... by rHOnDO

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.