in reply to Re^2: perl ST sort performance issue for large file?
in thread perl ST sort performance issue for large file?

It would be far easier to advise you if you would post the code you are using.

Often, the most innocent looking pieces of code conceal things that unnecessarily consume memory.

For example, the convenient: my @array = <$fh>; uses twice as much memory as:

my @array; my $n = 0; $array[ $n++ ] = $_ while <$fh>;

Because in the first version, <$fh> first creates a list of the lines on the stack, which are then assigned to the array. For a breif time, you have two copies of the entire file in memory, with the obvious increase in total memory requirement.

In the second version, the array is populated directly thus avoiding that problem.

For the majority of uses, the first form is convenient and not a problem, but when you are butting your head against the capacity of your hardware, the change is worth the effort.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^4: perl ST sort performance issue for large file?
by rkshyam (Acolyte) on Apr 03, 2012 at 16:15 UTC
    Here is the modified code to my earlier code.(Earlier also I have post +ed the code and as per perl monk i have updated and posted here) use strict; use warnings; use POSIX my $file_duplicate="log_duplicate_remove"; my $file_consolidated_sort="log_consolidated_sort"; open FH_duplicate, "$file_duplicate" or die "$!"; ### input file open FH_sorting, ">>$file_consolidated_sort" or die "$!"; #### out +put file my %hash = (); my $key; my $val; while(<FH_duplicate>) { chomp; ($key,$val)=split(/,,/); $hash{$key} .= $val; } close FH_duplicate; for $key(sort keys %hash) { print FH_sorting "$key -> $hash{$key}"; } close FH_sorting;