in reply to sorting a split hash

One solution is to also keep a second hash, a hash of array refs. For this hash, keys are the dates, and values are array refs of file names. You need an array because multiple files may share the same date. Sort the key of this second hash.

If the sole purpose of the first hash is to print this report, then forget about your first hash, and just use the hash I suggested here.

Also create the second hash, when you are creating the first one (by doing this, most likely you don't need to split '|').

Replies are listed 'Best First'.
Re^2: sorting a split hash
by coldfingertips (Pilgrim) on Oct 12, 2004 at 03:51 UTC
    Whoa there. I've never used hash refs or array refs before so I have zero clue what you were even saying.

    Any hints at where to go from here?

      This gives you the hash I talked about (just sort of one liner):

      use Data::Dumper; use strict; use warnings; my %h1 = ( "index.html" => "Mon Oct 11 00:08:11 2004|12963", "screenshot.jpg" => "Sun Oct 10 13:18:30 2004|234997", "legal.html" => "Mon Oct 11 12:57:03 2004|13448", "stylesheet.css" => "Mon Oct 11 13:57:28 2004|697", "about.html" => "Mon Oct 11 00:08:08 2004|13225", "archive.html" => "Mon Oct 11 00:08:09 2004|12872", "postinfo.html" => "Fri Oct 1 23:49:15 2004|2457", "contact.shtml" => "Mon Oct 11 00:09:48 2004|11366", "services.html" => "Mon Oct 11 00:08:17 2004|14256", "metatags.pl" => "Mon Oct 11 14:05:44 2004|28668", "tools.html" => "Mon Oct 11 15:35:47 2004|14632", "robots.txt" => "Sat Oct 9 03:35:15 2004|73", "_vti_inf.html" => "Fri Oct 1 23:49:15 2004|1754", "report.shtml" => "Mon Oct 11 00:07:03 2004|11686" ); my $h2; push @{$h2->{(split(/\|/, $h1{$_}))[0]}}, $_ for (keys(%h1)); print Dumper($h2);

      Output:

      $VAR1 = { 'Sat Oct 9 03:35:15 2004' => [ 'robots.txt' ], 'Mon Oct 11 14:05:44 2004' => [ 'metatags.pl' ], 'Mon Oct 11 00:09:48 2004' => [ 'contact.shtml' ], 'Mon Oct 11 00:08:08 2004' => [ 'about.html' ], 'Mon Oct 11 12:57:03 2004' => [ 'legal.html' ], 'Mon Oct 11 15:35:47 2004' => [ 'tools.html' ], 'Fri Oct 1 23:49:15 2004' => [ '_vti_inf.html', 'postinfo.html' ], 'Mon Oct 11 00:08:09 2004' => [ 'archive.html' ], 'Mon Oct 11 00:08:17 2004' => [ 'services.html' ], 'Mon Oct 11 00:07:03 2004' => [ 'report.shtml' ], 'Mon Oct 11 00:08:11 2004' => [ 'index.html' ], 'Sun Oct 10 13:18:30 2004' => [ 'screenshot.jpg' ], 'Mon Oct 11 13:57:28 2004' => [ 'stylesheet.css' ] };