Hi, I have two files FILE-1 & FILE-2 in given format.

FILE-1

CLAYCOUNTY;Wood;statecode=FL CLAYCOUNTY;Wood;statecode=FL SUWANNEECOUNTY;Wood;statecode=FL SUWANNEECOUNTY;Wood;statecode=TX SUWANNEECOUNTY;Wood;statecode=TX SUWANNEECOUNTY;Wood;statecode=TX NASSAUCOUNTY;Wood;statecode=UT

Step 1: Parse file FILE-1 with search key "Wood" and store the file columns into hash. I want to use 2nd and 3rd column and put it into a hash. with the 2nd column being the keys and 1st column being the distinct values.

e.g. for Key "Wood" values are
CLAYCOUNTY,
SUWANNEECOUNTY,
NASSAUCOUNTY

open (my $fh, "<", $file) or die "Can't open the file $file: "; while (<$fh>) { my $line = $_ if /\bWood\b/; chomp ($line); last if !$line; %hash2 = (%hash2 , (split(/;/, $line)),[1,0]); } print Dumper \%hash2;

FILE-2 Format as below

119736;Residential;CLAYCOUNTY 448094;Residential;CLAYCOUNTY 206893;Residential;CLAYCOUNTY 333743;Residential;CLAYCOUNTY 172534;Residential;CLAYCOUNTY 785275;Residential;CLAYCOUNTY 995932;Residential;CLAYCOUNTY 223488;Residential;CLAYCOUNTY 433512;Residential;CLAYCOUNTY 640802;Residential;SUWANNEECOUNTY 403866;Residential;SUWANNEECOUNTY 828788;Residential;SUWANNEECOUNTY 751490;Residential;SUWANNEECOUNTY 972562;Residential;SUWANNEECOUNTY 367541;Residential;SUWANNEECOUNTY 481360;Residential;SUWANNEECOUNTY 920232;Residential;NASSAUCOUNTY 727659;Residential;NASSAUCOUNTY 471817;Residential;NASSAUCOUNTY 983043;Residential;NASSAUCOUNTY 578286;Residential;NASSAUCOUNTY

Step 2: From above step take the column 1 distict value if FILE-1 and find all the values in column 1 of my FILE-2 and write them to output file.
In FILE-2 I want to use the 3rd and 1st column, with the 3rd column being key and 1st column being the values.

e.g. For key
CLAYCOUNTY values are 119736, 448094, 206893, 333743, 172534, 785275, 995932, 223488, 433512
SUWANNEECOUNTY are 640802,403866,828788,751490,972562,367541,481360
NASSAUCOUNTY are 920232,727659, 471817, 983043, 578286

Please provide suggestions to move ahead on this. Thanks.

In reply to Print hash keys and lookup the keys for values in another filr by Magnolia25

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.