Really, does it matter? It's like asking the most efficient way to close your car door to minimize the time of your Miami to New York road trip. | [reply] |
There is a lot of files that's going to be opened a lot of times, so I just want to be sure that this link in the chain is optimal
The thing I'm most concerned with is the best way to put the file in the variable. I do it in a clumsy way today.
open(FILE, "<test.txt");
@myfile = <FILE>;
close(FILE);
foreach $myrow (@myfile)
{
$result .= $myrow;
}
return $result;
I just want to do that in a better way :-) | [reply] [d/l] |
my $text = do {local $/; <FILE>};
Or you can use sysread, but you'll have to benchmark if that's faster.
You also may be able to tweak your filesystem/volumemanager/storagemanager to get a better performance. After all, your road trip gets shorter if you make use of tarmac roads instead of dirt roads. Regardless of the car you use, or your driving skills. | [reply] [d/l] [select] |
As the Anonymous Monk already said, you can use open or sysopen, but there probably won't be much difference, as most likely the majority of the time is spent in the underlying system call open(2), i.e. outside of the Perl program/in the kernel.
If you really want to know: Benchmark.
| [reply] |