in reply to Hash key ordering question

Ummm, the numbers are sequential, so why not use an array?
for ($i = 0; $i < 10; $i++) { $hash{2823}[$i] = "2823_$i.xml"; } foreach $key (keys %hash) { foreach $xml (0..$#{$hash{$key}}) { print "Key: $key/$xml => " . $hash{$key}[$xml] . "\n"; } } Key: 2823/0 => 2823_0.xml Key: 2823/1 => 2823_1.xml Key: 2823/2 => 2823_2.xml Key: 2823/3 => 2823_3.xml Key: 2823/4 => 2823_4.xml Key: 2823/5 => 2823_5.xml Key: 2823/6 => 2823_6.xml Key: 2823/7 => 2823_7.xml Key: 2823/8 => 2823_8.xml Key: 2823/9 => 2823_9.xml
JK

Replies are listed 'Best First'.
Re: Re: Hash key ordering question
by hardburn (Abbot) on May 07, 2003 at 19:22 UTC

    I would guess the datastructure is part of a larger program where an array doesn't make sense.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated