Hi all, I am new to Perl and having difficulty solving a problem. I'm trying to:
-take a few files of text as input
-pare the text down to reveal only a license plate i.d. that is three letters and three numbers, e.g., ABC 123
-license plates are "grouped" (for output) according to their letter sequence, so proper output would look like:
ABC 123, 334, 442
FTE 442
HHR 443
NTR 554, 554
I'm mostly having trouble making a hash of a hash. I know that it can be done with a hash of arrays (which I also was having trouble with), but I want to do it with a hash of hashes, if possible. Here's my code:
#! usr/bin/perl while (<>) { $input = $_; #I strip the raw input of extraneous info to #get the letters and numbers which are each #made into variables #This part of the code is working well and is thus omitted $lets = $input; $nums= $input; $plates{$lets} = $nums{0}; } foreach $licPlate (keys %plates) { print "$licPlate "; }
I had it where it was printing the same license plate numbers for all entries, but I changed the code and am not sure how I was even doing that. How do I properly make a hash of a hash from inputted files? How do I then output this in the form I showed above? I see how to get the keys out for the letter part of the license plates, but I'm stuck with how to show more than one set of numbers per letter group, or how to get each plate number to print out instead of one plate number printing out for each letter group. Thank you very much for any help given!

In reply to hash of hashes by volcan

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.