in reply to Re: XML::Simple Not Sorting
in thread XML::Simple Not Sorting

Here's the datastructure that I'm tring to sort.
$VAR1 = { 'policies' => [ { 'name' => 'ZAbc', 'link_name' => '7080-A103 zAbc.doc', 'description' => 'This is where the descript +ion goes.', 'policy_number' => '7080-A103' }, { 'name' => Def', 'link_name' => '7080-D100 ef.doc', 'description' => 'This is where the descript +ion goes.', 'policy_number' => '7080-D100' }, { 'name' => Pqrs', 'link_name' => '7080-E102 Pqrs.doc', 'description' => 'This is where the descript +ion goes.', 'policy_number' => '7080-E102' } ], 'title' => 'Test Policies', 'folder' => 'Title' };
Shortened to get to the point.

Replies are listed 'Best First'.
Re^3: XML::Simple Not Sorting
by jeffa (Bishop) on Jun 25, 2004 at 20:32 UTC

    Try this:

    use Data::Dumper; for ( sort { $a->{policy_number} cmp $b->{policy_number}} @{ $VAR1->{p +olicies} }) { print Dumper $_; }
    Which yielded the following for me: (even though the data was already sorted by 'policy_number')
    $VAR1 = { 'name' => 'ZAbc', 'description' => 'This is where the description goes.', 'link_name' => '7080-A103 zAbc.doc', 'policy_number' => '7080-A103' }; $VAR1 = { 'name' => 'Def', 'description' => 'This is where the description goes.', 'link_name' => '7080-D100 ef.doc', 'policy_number' => '7080-D100' }; $VAR1 = { 'name' => 'Pqrs', 'description' => 'This is where the description goes.', 'link_name' => '7080-E102 Pqrs.doc', 'policy_number' => '7080-E102' };

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)