in reply to modify the order a list with the help of a hash table
use warnings; use strict; use Cwd; my $path=cwd(); my %Hash; my $line; my $seconds=0; my $pathC = $path . '/data.txt'; open INFILE, "$pathC" or die "Cant open file $pathC\n"; while ($line = <INFILE>) { if($line =~ m/.*(\d{2}):(\d{2}):(\d{2}).*/){ $seconds = 3600*$1+60*$2+$3; $Hash{$seconds}=$line; } } close INFILE; for my $key (sort { $a <=> $b } (keys %Hash)){ print "$Hash{$key}"; }
|
|---|