Oh esteemed Monks, I come to you once again.

I have a file that has this output in it:


L01783 NETAPP-DAILY CLOSED-C5
L01456 WIN-DAILY CLOSED-C5
L00378 NETAPP-DAILY CLOSED-C5
L01799 NETAPP-DAILY CLOSED-C5
L00543 NETAPP-WEEKLY CLOSED-C5
L01458 WIN-DAILY CLOSED-C5
L01459 UNIX-DAILY CLOSED-C5
L01797 NETAPP-MONTHLY PROGRAM-P5
L01431 NETAPP-DAILY CLOSED-C5
L00425 WIN-WEEKLY CLOSED-C5
L00277 NETAPP-MONTHLY CLOSED-C5
L00588 UNIX-DAILY CLOSED-C5
L01468 NETAPP-DAILY CLOSED-C5
L01780 UNIX-DAILY CLOSED-C5
L01782 NETAPP-MONTHLY PROGRAM-P5
L01288 NETAPP-WEEKLY CLOSED-C5
L01293 NETAPP-MONTHLY PROGRAM-P5
L01784 NETAPP-MONTHLY PROGRAM-P5
L01121 NETAPP-DAILY CLOSED-C5

I have a hash called %tapes. The key in this hash is L001121 and the value is NETAPP-DAILY CLOSED-C5. (One key/value for each line in the file.)

What I need to do is output a new file after removing some lines. I can do this just fine, but I have a sorting problem. I need to sort this has based on the "C5" and "P5" parts. So the final data should look like this:

L01783 NETAPP-DAILY CLOSED-C5
L01456 WIN-DAILY CLOSED-C5
L00378 NETAPP-DAILY CLOSED-C5
L01799 NETAPP-DAILY CLOSED-C5
L00543 NETAPP-WEEKLY CLOSED-C5
L01458 WIN-DAILY CLOSED-C5
L01459 UNIX-DAILY CLOSED-C5
L01431 NETAPP-DAILY CLOSED-C5
L00425 WIN-WEEKLY CLOSED-C5
L00277 NETAPP-MONTHLY CLOSED-C5
L00588 UNIX-DAILY CLOSED-C5
L01468 NETAPP-DAILY CLOSED-C5
L01780 UNIX-DAILY CLOSED-C5
L01288 NETAPP-WEEKLY CLOSED-C5
L01121 NETAPP-DAILY CLOSED-C5
L01797 NETAPP-MONTHLY PROGRAM-P5
L01782 NETAPP-MONTHLY PROGRAM-P5
L01293 NETAPP-MONTHLY PROGRAM-P5
L01784 NETAPP-MONTHLY PROGRAM-P5

Thanks in advance for your help!
Thanks so much to everyone! I don't know why I didn't think of using substr to compare the values, I guess I just need more experience programming perl. Anyway, this was a huge help and now I've got it working perfectly. Thanks again!

In reply to Crazy hash sorting issue. by rementis

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.