This seemed easy to me last night and for some reason I can't get this to work on my head, or in script.

I have a log file that looks like

Big Bird 10 20 40 50 Calvin Klein 45 30 100 80 10 Mother Natures 100 100 23
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.

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);

In reply to reading a log file and sorting by last name by Anonymous Monk

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.