#/usr/bin/perl -w use warnings; use strict; use Data::Dumper; my (@county,%result); my $inFile01 ="FILE01.dat"; #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 open(DATA01,'<',$inFile01)or die("Can't open input file\"$inFile01\":$ +!\n"); while (<DATA01>) { # Skipping if the line is empty or a comment next if ( $_ =~ /^\s*$/ ); next if ( $_ =~ /^#\s*/ ); my ($county,$srch,$stcode) = split(";",$_); chomp($srch,$county); if ($srch eq "Wood") { push (@county,$county) } } close(DATA01); my $inFile02 ="FILE02.dat"; #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 foreach my $cnty (@county) { my @countycode; open(DATA02,'<',$inFile02)or die("Can't open input file\"$inFi +le02\":$!\n"); while (<DATA02>) { # Skipping if the line is empty or a comment next if ( $_ =~ /^\s*$/ ); next if ( $_ =~ /^#\s*/ ); my ($code,$attr,$countyy) = split (";",$_); chomp ($code,$attr,$countyy); if ($countyy eq $cnty) { push @countycode, $code; } $result{$cnty} = [@countycode] } } close(DATA02); print Dumper \%result; foreach my $key (keys %result) { print "$key" . "\n"; my $op = join "|", @{$result{$var}}; print "$op" . "\n"; }

I am able to get thw desired values. One last thing with printing the output to an another file now which is required as below: for all the values in @{$result{$var}} I need to print as follows to a output file (No particular order) - for 119736 Need two lines in file as below (similarly for all).

L|A|119736|119736||||||||||||||||||||||| M|A|119736||||Wood|Wood|CONSTANT_STRING

complete file looks like

L|A|119736|119736||||||||||||||||||||||| M|A|119736||||Wood|Wood|CONSTANT_STRING L|A|448094|119736||||||||||||||||||||||| M|A|448094||||Wood|Wood|CONSTANT_STRING L|A|206893|206893||||||||||||||||||||||| M|A|206893||||Wood|Wood|CONSTANT_STRING L|A|333743|333743||||||||||||||||||||||| M|A|333743||||Wood|Wood|CONSTANT_STRING L|A|172534|172534||||||||||||||||||||||| M|A|172534||||Wood|Wood|CONSTANT_STRING ..... .... ....
Thanks.

In reply to Re^2: Print hash keys and lookup the keys for values in another file -- oneliner and more explained by Magnolia25
in thread 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.