On Thu, Sep 3, 2015 at 9:42 AM, Gary Stainburn <gary.stainb...@ringways.co.uk> wrote: > I have a hash of hashes which I converted to an array of hashes because I > needed to access them in a specific sequence. It now looks like > > my @pagetypes=( > {'pagetype'=>'Delivery Note','weight'=>2,..... > {'pagetype'=>'Sales Invoice','weight'=>2,..... > {'pagetype'=>'Purchase Invoice','weight'=>2,..... > .......... > > I then access the array using > > foreach my $pt (@pagetypes) { > > > However, I have now lost the ability to access each pagetype by it's name > > I am aware that you cannot define a key sequence when defining a hash. > However, if I create a sequence field > > my %pagetypes=( > 'Delivery Note'=>{'seq'=>1,weight'=>2,..... > 'Sales Invoice'=>{'seq'=>2,'weight'=>2,..... > 'Purchase Invoice'=>{'seq'=>3,'weight'=>2,..... > .......... > > How can I do the foreach statement to access them in the correct sequence? >
If the 'seq' items just maintain insertion order, then: use Tie::IxHash; use feature 'say'; tie( my %pagetypes, 'Tie::IxHash') or die $!; %pagetypes=( 'Delivery Note' => ..., Foo=>, Bar=>); foreach my $pagetype (keys %pagetypes) { ... } say $pagetypes{'Delivery Note'}{weight}; -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/