Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
open(FILE, "<$ARGV[0]") || die "$!"; count_bases(20); count_bases(30); ... sub count_bases { seek FILE, 0, SEEK_SET; #reset file pointer my $min_quality = shift; foreach $line (<FILE>) #main loop { my @tmp_ar = split("\t", $line); ... #make comparisons and put #s in hash }
but this ended up being too slow. I run this on a remote server (which I do not have admin) and it always gets killed after locking up the server for a couple of minutes. I looked over a similar script (that I did not write) and noticed that they used while(<>) to read things in. This script was not killed by the server when processing the same large file. So I make the following changes
count_bases(20, $ARGV[1]); count_bases(30, $ARGV[1]); ... sub count_bases { my $min_quality = shift; while(<>) { my @tmp_ar = split(); ... #make comparisons and put #s in hash }
This however does not work for the 2nd count_bases call, it just freezes after the 1st. I am guessing that the while(<>) takes from @ARGV and not the values that I pass into the function so after it uses the 1st time it never starts the end.
my questions: why is the implicit open so much faster? is there a way to get implicit open to work twice? is there a way to make the 1st way fast without implicit open?
thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Efficiently processing a file
by jwkrahn (Abbot) on Jan 25, 2010 at 22:28 UTC | |
by Anonymous Monk on Jan 25, 2010 at 22:37 UTC | |
by rkrieger (Friar) on Jan 26, 2010 at 07:51 UTC | |
by jwkrahn (Abbot) on Jan 25, 2010 at 22:45 UTC | |
by Anonymous Monk on Jan 26, 2010 at 17:03 UTC | |
|
Re: Efficiently processing a file
by ahmad (Hermit) on Jan 25, 2010 at 22:27 UTC | |
|
Re: Efficiently processing a file
by Anonymous Monk on Jan 25, 2010 at 22:26 UTC | |
by ahmad (Hermit) on Jan 25, 2010 at 22:33 UTC |