John W. Krahn wrote:
> Rob Dixon wrote:
>>
>> Nelson Ray wrote:
>>> Just as a little background, I am working on a BioInformatics
>>> program that runs on large (about 300 meg) text files.  I am using a
>>> filehandle to open and load it into an array.  Then I use the join
>>> command to read the array into a scalar variable in order to be in a
>>> workable form for my computationally intensive program.
>>
>> My first thought is that you're wasting space here by duplicating the
>> file's contents into both the array and the scalar. Just read
>> directly into the scalar (by enabling 'slurp' mode) like this:
>>
>>     my $contents;
>>     {
>>         local $/;
>>         open FILE, "< file.txt";
>
> You should _always_ verify that the file opened successfully.

Sure, but that's not what the question was about. You should always add
'use strict' and 'use warnings' too, but I didn't put that in either.

>
>>         $contents = <FILE>;
>>         close FILE;
>>     }
>
> my $contents = do {
>         open my $fh, 'file.txt' or die "Cannot open 'file.txt' $!";
>         local $/; <$fh> };

Yes, so would I. But it's more likely to confuse than assist I think.

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to