This still doesn't make sense. If you add print "File count is: $file_count \n"; You'll find that $file_count is always 0, because after reading the files with while (<>), @ARGV is always empty. And you check the size of the array in $seen{$key1}, but it always is 2 (there are two elements, Key, and Sum).my $file_count = @ARGV; foreach my $key1 ( keys %seen ) { if ( @{ $seen{$key1} } >= $file_count) { print join( "\t", @{$seen{$key1}}); print "\n\n"; } }
When you use while (<>) to read from a list of files, the current file is $ARGV.
# At the top of the file use constant { Key => 0, Sum => 1, Count => 2, # Remove this if you don't use the total count Files => 3 # Should be 2 if Count is not used. };
# In the read loop $seen{$key1}[Key] //= $key; $seen{$key1}[Sum] += $value; $seen{$key1}[Count]++; # Total count for the number of times t +his value exists $seen{$key1}[Files]{$ARGV}++; # Count in this file
You don't seem to want a particular format for your output (because you changed it when adapting my proposition), so you could try just dumping the whole structure using either Data::Dumper (nothing to install) or YAML (needs to be installed, but can be nicer to read).
Oruse Data::Dumper; while (<>) { # Your code here } print Dumper(\%seen);
use YAML; while (<>) { # Your code here } print YAML::Dump(\%seen);
In reply to Re^3: merge multiple files giving out of memory error
by Eily
in thread merge multiple files giving out of memory error
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |