Rob Dixon wrote:
> 
> John W. Krahn wrote:
> > Rob Dixon wrote:
> >>
> >>         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.

So, reading from an unopened filehandle would not be confusing?  IHMO
when dealing with a person who is not as familiar with Perl, it is
better to use "correct" code examples[1].  If the OP does not understand
they can always ask subsequent questions here.



[1]  http://www.acm.org/serving/se/code.htm
     http://computer.org/certification/ethics.htm

John
-- 
use Perl;
program
fulfillment

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

Reply via email to