Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have a log file that looks like
I need to open this log file, sort my last name alphabetically, and print everything out. Easy? I knew it was but my mind is playing tricks on me.Big Bird 10 20 40 50 Calvin Klein 45 30 100 80 10 Mother Natures 100 100 23
My original thought was to split it by spaces at first so I can get the two names, and all the numbers in one var since they're not important to have separate. Then create a new array to store the new results in an order I can sort. From there, just print it out.
The problem I am running into is the digits, I can't capture all of them no matter what I've tried.
Can someone help me find a solution and let me know why my solutions weren't working?
open (LOG, $log) or die "Error: $!"; my @lines = <LOG>; close(LOG) or die "Error: $!"; my @good_results; foreach my $key (@lines) { # my ($fname, $lname, $grades) = split(/\w+/, $key); my ($fname, $lname) = split(/ /, $key); $key =~ m/\w+\s+(\d+\s)$/; my $grades = $1; print "$lname and $fname $grades\n"; #push(@good_results, "$lname $fname $grades"); } #print join("\n", sort @good_results);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reading a log file and sorting by last name
by Limbic~Region (Chancellor) on Oct 09, 2006 at 15:46 UTC | |
|
Re: reading a log file and sorting by last name
by jdporter (Paladin) on Oct 09, 2006 at 15:55 UTC | |
by Hue-Bond (Priest) on Oct 09, 2006 at 16:01 UTC | |
|
Re: reading a log file and sorting by last name
by Anonymous Monk on Oct 09, 2006 at 15:42 UTC | |
by jwkrahn (Abbot) on Oct 09, 2006 at 16:06 UTC |