in reply to reading a log file and sorting by last name
It does assume last names are unique. If this is not the case, you could always use a two level hash $name{$ln}{$fn} and if that still is not unique you could use $rest as in $name{$ln}{$fn}{$rest}.my $log_file = $ARGV[0] || 'log.file'; open(my $fh, '<', $log_file) or die "Unable to open '$log_file' for re +ading: $!"; my %name; while (<$fh>) { chomp; my ($fn, $ln, $rest) = $_ =~ /^(\w+)\s+(\w+)(.*)/; $name{$ln} = "$ln $fn$rest\n"; } for (sort keys %name) { print "$name{$_}"; }
Cheers - L~R
|
|---|