On Thursday 03 September 2015 21:50:54 Marius Gavrilescu wrote: > gary.stainb...@ringways.co.uk (Gary Stainburn) writes: > > On Thursday 03 September 2015 18:19:57 Marius Gavrilescu wrote: > >> The above can be shortened using the Sort::Key module. > >> > >> use Sort::Key 'nkeysort'; > >> for my $key (nkeysort { $pagetypes{$_} } keys %pagetypes) { > >> # do stuff with $pagetypes{key} here > >> } > > > > This intrigues me as I can't see where you specify the sequence field. > > I'll go Googling > > You can't see it because I forgot to specify it >_< > > Replace '$pagetypes{$_}' with '$pagetypes{$_}{seq}' and it *should* work. > -- > Marius Gavrilescu
Thanks for that Marius. I worked that out from the perldocs. However, I decided to go with a variant of Slomi's method. The down side to working this way is that I have to manually maintain the SEQ field, and if I need to add a row in the middle, all subsequent rows need amending. Also, changing back from an array of hashes to hash of hashes meant lots of code changes elsewhere. Instead I've achieved what I needed with the following code: my %pt_index; for (my $i=0;$i<@page_types;$i++) { $pt_index{$page_types[$i]{'pagetype'}}=$i; } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/