<?xml version="1.0" encoding="windows-1252"?>
<node id="948635" title="Re: Extracting information from file to Hash" created="2012-01-18 17:15:12" updated="2012-01-18 17:15:12">
<type id="11">
note</type>
<author id="171588">
BrowserUk</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;If you use an array of hashes, the sorting becomes quite intuitive:&lt;code&gt;
#! perl -slw
use strict;
use Data::Dump qw[ pp ];

my @data;
while( &lt;DATA&gt; ) {
    my( $col, $cnt, $stat, $miss, $mod ) = m[
        ^
        Collection=&gt;(\d+) \s+
        ImageCount=&gt;(\d+) \s+
        Status=&gt;(\w+ ) \s+
        Missing=&gt;( [1-9,]+ )? \s+
        Modified=&gt;( .+ )
        $
    ]x or warn "Bad format at line $.\n" and next;

    my( $day, $mon, $year, $hrs, $min, $sec ) = 
        $mod =~ m[(\d+)/(\d+)/(\d+) (\d+):(\d+):(\d+)]
        or warn "Bad date format in line $." and next;

    push @data, {
        Collection =&gt; $col,
        ImageCount =&gt; $cnt,
        Status =&gt; $stat,
        Missing =&gt; [ split ',', $miss||'' ],
        Modified =&gt; sprintf( "%4d/%02d/%02d %02d:%02d:%02d",
            $year, $mon, $day, $hrs, $min, $sec ),
    };
}

##pp 'original order',  \@data;

## Sort data by image count descending and modified date ascending
my @ordered = sort {
    $data[ $b ]{ ImageCount } &lt;=&gt; $data[ $a ]{ ImageCount }
    ||
    $data[ $a ]{ Modified } cmp $data[ $b ]{ Modified }
} 0 .. $#data;

print  'Sorted by Image count descending and modified date ascending';
pp $data[ $_ ] for @ordered;

__DATA__
Collection=&gt;168245 ImageCount=&gt;6 Status=&gt;SI Missing=&gt;1,3 Modified=&gt;01/18/2012 11:14:30
Collection=&gt;161745 ImageCount=&gt;6 Status=&gt;I Missing=&gt;2,3 Modified=&gt;01/18/2012 11:16:38
Collection=&gt;162451 ImageCount=&gt;6 Status=&gt;SC Missing=&gt; Modified=&gt;01/20/2012 11:16:38
Collection=&gt;117481 ImageCount=&gt;8 Status=&gt;C Missing=&gt; Modified=&gt;01/18/2011 7:16:38
&lt;/code&gt;

&lt;P&gt;Produces:&lt;code&gt;
C:\test&gt;junk53
Sorted by Image count descending and modified date ascending
{
  Collection =&gt; 117481,
  ImageCount =&gt; 8,
  Missing    =&gt; [],
  Modified   =&gt; "2011/18/01 07:16:38",
  Status     =&gt; "C",
}

{
  Collection =&gt; 168245,
  ImageCount =&gt; 6,
  Missing    =&gt; [1, 3],
  Modified   =&gt; "2012/18/01 11:14:30",
  Status     =&gt; "SI",
}

{
  Collection =&gt; 161745,
  ImageCount =&gt; 6,
  Missing    =&gt; [2, 3],
  Modified   =&gt; "2012/18/01 11:16:38",
  Status     =&gt; "I",
}

{
  Collection =&gt; 162451,
  ImageCount =&gt; 6,
  Missing    =&gt; [],
  Modified   =&gt; "2012/20/01 11:16:38",
  Status     =&gt; "SC",
}
&lt;/code&gt;

&lt;div class="pmsig"&gt;&lt;div class="pmsig-171588"&gt;
&lt;hr /&gt;
&lt;font size=1 &gt;
&lt;div&gt;With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'&lt;/div&gt;
&lt;div&gt;Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.&lt;/div&gt;
&lt;div&gt;"Science is about questioning the status quo. Questioning authority". &lt;/div&gt;
&lt;div&gt;In the absence of evidence, opinion is indistinguishable from prejudice.
&lt;p align=right&gt;[http://www.theregister.co.uk/2011/11/29/sas_versus_world_programming/|The start of some sanity?]&lt;/p&gt;&lt;/div&gt;
&lt;/font&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
948626</field>
<field name="parent_node">
948626</field>
</data>
</node>
