A self-contained example solution using the HoH you were thinking of.

johngg@shiraz:~/perl/Monks > perl -Mstrict -Mwarnings -E ' open my $file1FH, q{<}, \ <<__EOD1__ or die $!; App1,4,Perl App2,8,Java App3,8,Java App4,4,PHP App5,8,C# __EOD1__ my %apps; while ( <$file1FH> ) { chomp; my( $key, $mem, $lang ) = split m{,}; $apps{ $key }->{ mem } = $mem, $apps{ $key }->{ lang } = $lang; } close $file1FH or die $!; open my $file2FH, q{<}, \ <<__EOD2__ or die $!; App1,1.5,2 App2,2.5,4 App3,2.8,4 App4,2.8,2 App5,2.8,2 __EOD2__ while ( <$file2FH> ) { chomp; my( $key, $cpu, $cores ) = split m{,}; $apps{ $key }->{ cpu } = $cpu; $apps{ $key }->{ cores } = $cores; } say for sort { $apps{ $a }->{ mem } <=> $apps{ $b }->{ mem } } grep { $apps{ $_ }->{ cores } eq q{2} } sort keys %apps;' App1 App4 App5

I hope this is useful.

Update: Corrected spelling mistake and added the following note:-

The reason I sort the keys before passing them into the grep is that the order returned by the keys function is essentially random. Since Perl's sort is "stable" it would not change the order in which "App1" and "App4" appeared as they have the same memory value so a result of

App4 App1 App5

could happen.

Cheers,

JohnGG


In reply to Re: Multiple File handling and merging records from 2 files by johngg
in thread Multiple File handling and merging records from 2 files by kris1511

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.