My guess is that the code that you are actually using looks more like
sub read_file {
my $file=shift;
open my $fh,$file or die "$file : $!";
my @lines=<$fh>;
return \@lines;
}
In which case its storing the data in memory. Which is perhaps overflowing your available physical ram. When that happens the OS starts swapping the memory out to disk (obviously a slow operation), which if it happens enough leads to a condition called thrashing where the OS is basically just moving memory back and forth from the disk, and the time taken for the repeated swapping completely overwhelms the time your code takes. Causing your code to look like it hangs. Try using some memory monitoring tool, or do some program analyiss to see exactly how much memory you are actually using. Hashes for instance consume far far more memory than they look. As does careless array manipulation. For instance if you have
my @array;
$array[100_000_000]=1;
then perl will have to allocate sufficient RAM for all 100 million slots, even though they arent used.
Without seeing real code, (as i said I dont think what you posted properly reflects what you are doing) its hard to say for certain.
Regards,
UPDATE: Since you are on Win2k you should take advantage of the Task manager and the Profiler that come with the OS. (Start -> Settings -> Control Panel -> Administrative Tools -> Profiler)
--- demerphq
my friends call me, usually because I'm late....
|