Thanks a lot apl

Here is the program to take into account your remarks. However, there is still a problem.

#! perl -slw use strict; use diagnostics; use Data::Dump qw[ pp ]; sub by_hour{ my ($a,$b) = @_; my $h_a; my $mn_a; my $h_b; my $mn_b; my $res; if ($a =~ /(\d\d):(\d\d)/){ $h_a = $1; $mn_a = $2; } if ($b =~ /(\d\d):(\d\d)/){ $h_a = $1; $mn_a = $2; } if ($h_a < $h_b){ $res = -1; } if ($h_a > $h_b){ $res = 1; } if ($h_a == $h_b){ if ($mn_a < $mn_b){ $res = -1; } if ($mn_a > $mn_b){ $res =1; } if ($mn_a == $mn_b){ $res = 0; } } return $res; } my %in; while (<DATA>){ m[(\d\d:\d\d) (.+)$] and push @{ $in{ $1 } }, $2; } my @keys = keys %in; my @times = sort @keys; for my $hr ( sort by_hour keys %in ) { print STDOUT "$hr\n"; } __DATA__ 11:10 A1 12:30 E4 11:30 Z4 15:50 H5 12:02 H6 12:25 B2 11:25 A8 12:30 F3 14:30 E7 12:50 E15 12:55 E16

In reply to Re^2: sub routine to sort per time by steph_bow
in thread sub routine to sort per time by steph_bow

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.