The code which I have posted is quite close to what I am doing. my appliction has couple of log files. I tried to write a generic fuction which will open a log file and return all its contents. However I realized my application slows down a lot when the second call to the log reader function is made.
Then I wrote this dummy program. The function here and the one in my application are the same.
I tried to optimize the code by passing a reference to the @lines array to the function and using the same reference everywhere. but that did not help. My machine has 512 MB physical ram and 756 MB swap pagefile. So I don't think that hardware or swap is an issue. Just to check if the OS is s*wing up, I wrote the same function in C#. There all the 3 function calls took 5 seconds each. So why is it in perl that the second and third calls take so long? I am still confused.
my updated code looks likeregards, Abhishek.use strict; use warnings; print "opening file 1\n"; my @lines; myfile(\@lines); @lines = {}; print "opening file 2\n"; myfile(\@lines); @lines = {}; print "opening file 3\n"; myfile(\@lines); @lines = {}; sub myfile { my ($line) = @_; open my $fh, "xml.log"; @{$line}= <$fh>; close($fh); }
In reply to Re: Re: Re: Re: opening a file in a subroutine
by abhishes
in thread opening a file in a subroutine
by abhishes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |