Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Totally from scratch:</p> <p>Printed Output:</p> <pre><code>Unsorted: 14-OCT-06 15-OCT-06 13-OCT-06 19-FEB-12 29-DEC-02 15-JAN-02 Sorted (Least recent to most recent): 15-JAN-02 29-DEC-02 13-OCT-06 14-OCT-06 15-OCT-06 19-FEB-12 </code></pre> <p>Code:</p> <pre><code>#!C:\Perl64 #Input Strings @inputs = ('14-OCT-06','15-OCT-06','13-OCT-06', '19-FEB-12', '29-DEC-02', '15-JAN-02'); print "Unsorted:\n"; foreach(@inputs){ print $_."\n"; } # Hash for Month : Number %months = ('JAN' =&gt; '01', 'FEB' =&gt; '02', 'MAR' =&gt; '03', 'APR' =&gt; '04', 'MAY' =&gt; '05', 'JUN' =&gt; '06', 'JUL' =&gt; '07', 'AUG' =&gt; '08', 'SEP' =&gt; '09', 'OCT' =&gt; '10', 'NOV' =&gt; '11', 'DEC' =&gt; '12'); # Hash for Number : Month %revmonths = ('01'=&gt;'JAN', '02' =&gt; 'FEB', '03' =&gt; 'MAR', '04' =&gt; 'APR', '05' =&gt; 'MAY', '06' =&gt; 'JUN', '07' =&gt; 'JUL', '08' =&gt; 'AUG', '09' =&gt; 'SEP', '10' =&gt; 'OCT', '11' =&gt; 'NOV', '12' =&gt; 'DEC'); # Rearrange the order to 'Year-Month-Day' @dates = (); foreach(@inputs){ my @split = split('-',$_); my @rearranged = reverse(@split); @rearranged[1] = $months{$rearranged[1]}; push(@dates, \@rearranged); } # Sort based on these three fields @sorted = sort { $a-&gt;[2] &lt;=&gt; $b-&gt;[2] } @dates; @sorted = sort { $a-&gt;[1] &lt;=&gt; $b-&gt;[1] } @sorted; @sorted = sort { $a-&gt;[0] &lt;=&gt; $b-&gt;[0] } @sorted; # Replace Month Number with Month name $size = @sorted; for $counter (0..$size-1){ my $ref = $sorted[$counter]; my @array = @$ref; my $num = $array[1]; $array[1] = $revmonths{$array[1]}; my @array = reverse(@array); $sorted[$counter] = \@array; } print "\nSorted (Least recent to most recent):\n"; foreach(@sorted){ my @temp = @$_; my $day = $temp[0]; my $month = $temp[1]; my $year = $temp[2]; print $day."-".$month."-".$year; print "\n"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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