balajinagaraju has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I am newbie to perl and i am stuck at some point where i wanted to sort a datastructure as shown below , its basically an array of hashes and i am clueless how to sort it. I need testcase1, 2 and 3 and so on in an order and i need the 'step' to be listed from step1 to stepN in increasing order and i also need to sort the values within each step if the parameters are similar to what is listed under step4, i need them in order from param1 to param4.. Can anyone help me in solving this.
my @array = ( 'testcase1' => { 'step2' => { 'command' => 'Goto' }, 'step1' => { 'param2' => 'dirpath', 'param1' => 'executablepath', 'command' => 'Launch ' }, 'step4' => { 'param4' => '580', 'param2' => '96', 'param3' => '726', 'param1' => '3', 'command' => 'CaptureRectanlge' }, 'step5' => { 'image1' => 'D:\\\\img1.jpg', 'image2' => 'D:\\\\img2.jpg ', 'command' => 'CompareImage' }, 'step3' => { 'param1' => '100', 'command' => 'Run' } }, 'testcase2' => { 'step2' => { 'command' => 'Goto' }, 'step1' => { 'param2' => 'dirpath', 'param1' => 'executablepath', 'command' => 'Launchsimulator ' }, 'step4' => { 'param4' => '580', 'param2' => '96', 'param3' => '726', 'param1' => '3', 'command' => 'CaptureRectanlge' }, 'step5' => { 'image1' => 'D:\\\\img1.jpg', 'image2' => 'D:\\\\img2.jpg ', 'command' => 'CompareImage' }, 'step3' => { 'param1' => '100', 'command' => 'Run' } }, 'testcase3' => { 'command6' => 'F', 'commandA' => 'J', 'command8' => 'H', 'command7' => 'G', 'command9' => 'I' }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sorting Array of hashes
by Happy-the-monk (Canon) on Apr 03, 2012 at 08:48 UTC | |
by balajinagaraju (Sexton) on Apr 03, 2012 at 09:17 UTC | |
|
Re: sorting Array of hashes
by nemesdani (Friar) on Apr 03, 2012 at 08:47 UTC | |
by balajinagaraju (Sexton) on Apr 03, 2012 at 09:18 UTC |