Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am going to one last time try to answer this as clearly as possible.</p> <p>First, if all timestamps are like <code>2008-08-07T22:31:06Z</code>, there is no need to map them through <code>UnixDate</code> as standard <code>sort</code> using <code>cmp</code> will sort them correctly.</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Date::Manip; my %args = ( car_models =&gt; { a =&gt; { year =&gt; '2009-08-07T22:31:06Z' }, b =&gt; { year =&gt; '2008-08-07T23:31:06Z' }, c =&gt; { year =&gt; '2008-08-07T21:31:06Z' }, }, ); my @sorted_cmp = sort { $a-&gt;{year} cmp $b-&gt;{year} } values %{ $args{car_models}}; print "Sorted *without* using UnixDate:\n"; print Dumper \@sorted_cmp; my @sorted_dm = sort { UnixDate($a-&gt;{year}, '%o') &lt;=&gt; UnixDate($b-&gt;{year}, '%o') } values %{ $args{car_models}}; print "Sorted using UnixDate:\n"; print Dumper \@sorted_dm; </code></pre> <p>Output (after setting <code>TZ</code> in <code>cmd</code> to placate <a href="http://search.cpan.org/perldoc/Date::Manip" rel="nofollow noreferrer"><code>Date::Manip</code></a>):</p> <pre> C:\Temp> cars Sorted *without* using UnixDate: $VAR1 = [ { 'year' => '2008-08-07T21:31:06Z' }, { 'year' => '2008-08-07T23:31:06Z' }, { 'year' => '2009-08-07T22:31:06Z' } ]; Sorted using UnixDate: $VAR1 = [ { 'year' => '2008-08-07T21:31:06Z' }, { 'year' => '2008-08-07T23:31:06Z' }, { 'year' => '2009-08-07T22:31:06Z' } ]; </pre> <p><em>No warnings</em>, <em>no errors</em> ... <em>Ergo</em>, all you have put on this page is one big mess of a red herring. Besides, this still does not explain where the <code>1249998666</code> in <a href="https://stackoverflow.com/questions/1267706/perl-hash-ref-error">your other question</a> came from.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload