If you're not going to use $tot when the value array is smaller than the number of input files, you do not need to compute it. You can move the inner for loop inside the if ( @{ $seen{$key1} } >= $file_count) block.
Anyway, when you get the file count through @ARGV, it is always 0, as the arguments have been shifted out of @ARGV by while(<>).

You can speed split a little by limiting the number of time it splits. Either with the LIMIT argument, or writing the output to a list with a defined length. Ex: (undef, my $key1) = split "\n", $key; and $tot += ( split ':', $val, 2)[0]. For the latter, I wouldn't be surprised if the subscript already limited the number of times splitting occurs but it is not explicitly stated as so in the doc. I'm not sure this will be a significant increase in speed, but your script is simple enough that there's not much that can be done.

I'm a little surprised to see that you write $key as the first value in your value array, but without sample data, what you are trying to parse with your script is not very clear.

Maybe you can check the list of files with something like:

die "File $_ does not exist" for grep { not -e } @ARGV; # make sure @A +RGV only contains filenames. warn '@ARGV is empty, the program will read from STDIN' unless @ARGV;
The second line will warn you if you ever forget to pass the file list in the parameters, as the script would seem to freeze when it is actually waiting on STDIN.


In reply to Re: modification of the script to consume less memory with higher speed by Eily
in thread modification of the script to consume less memory with higher speed by Anonymous Monk

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.