Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
Hi Monks,
I want to get the output of this hash array sorted by date.

Input for the hasharray

$dateOut = "2008-12-05"; $dSec = 0; $dMin=5; $dHour=9;
$dateOut = "2008-12-03"; $dSec = 2; $dMin=8; $dHour=5;
$dateOut = "2008-12-04"; $dSec = 0; $dMin=5; $dHour=8;

This is the part of code,
$dateOut = "$oDay".'-'."$oMon".'-'."$oYear"; #print"Date out => $dateOut\n"; $Date_Time{$dateOut}{$dSec}{$dMin}{$dHour} = 1 +; #Retrieving the hash array output foreach my $date ( sort keys %Date_Time ) { #print"Date=> $date\n"; foreach my $sec (sort keys %{$Date_Time{$date}}) { #print"Seconds=> $sec\n"; foreach my $minute (sort keys %{$Date_Time{$date}{$sec}}) +{ #print"Minute=> $minute\n"; foreach my $ hour (sort keys %{$Date_Time{$date}{$sec} +{$minute}}) { print"Date=>[$date] --> [$hour]:[$minute]:[$sec]\n +"; } } } } My Output: Date=>04-12-2008 --> 8:5:0 Date=>03-12-2008 --> 5:8:0 Date=>05-12-2008 --> 9:5:0 Expected output: Date=>03-12-2008 --> 5:8:0 Date=>04-12-2008 --> 8:5:0 Date=>05-12-2008 --> 9:5:0
Could any of you please help me to display the hash data sorted by date?

Thanks,
madtoperl

In reply to Sort Hash array using date by madtoperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.