sub by_time { # $a and $b are things to be compared from sort() # Convert $a and $b into integer values # Extract the time from the string into $a_v my ($a_v) = $a =~ / (\d\d?:\d\d:\d\d)/; # Remove colons to create a numeric-only value $a_v =~ tr/://d; # Same for $b my ($b_v) = $b =~ / (\d\d?:\d\d:\d\d)/; $b_v =~ tr/://d; # Return the difference (0 = same) return $a - $b; } foreach (sort by_time @stuff) { print "$_\n"; }
In reply to Re: How do you sort an array?
by tadman
in thread How do you sort an array?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |