note
serf
If you are concerned about the performance while reading the file into an array I would recommend doing some sample code and running it against a large file (say 100MB or more) to test the speed difference between doing:
<code>
@array = <FILE>;
</code>
and doing:
<code>
while(<FILE>) {
push(@array, $_);
}
</code>
and run it multiple times to make sure you're not just getting the effect of the file being cached in memory.
<p>I have found that while the version with the while loop *looks* longer it actually has always run faster in the tests I've done.
<p>PS: a die message with your open statement like
<code>
open (DF, "test.txt") || die "Can't read 'test.txt': $!\n"
</code>
is your friend, as are:
<code>
use strict;
use warnings;
</code>
at the top of your script - I'd recommend using them - they will help you by saving you time finding what's causing errors and in the long run should also help you to write better code by teaching you good habits.
<p>:o)
<p><b>update:</b> Thanks [ChOas] - I've fixed it. I always use the () brackets and || myself - and vaguely recalled (like you point out) that there *was* a difference between || and 'or'.
<p>After having [Dominus] do a [http://perl.plover.com/yak/flags/|presentation] to us the other week and finding I am in th habit of using () where I don't absolutely need to, I'd thought I'd not add them here where [NeilF] wasn't already using them... I've put them back on now :o)
<p>running:
<code>
perl -MO=Deparse -e 'open (DF, "test.txt") || die "Cant read test.txt\n";'
</code>
tells me I *could* write it:
<code>
die "Can't read test.txt\n" unless open DF, 'test.txt';
</code>
but I won't :o)
520201
520201