On 10/18/07, lists user <[EMAIL PROTECTED]> wrote:
>
> why it say a 'local *FH' here?
> why not just,
>
> open FH,$path or return undef;
> return *FH;
Because local would protect the global file-handle FH which maybe was
already opened out of the subroutine.
See this test,
use strict;
open HD,'/etc/hosts' or die $!;
{
local *HD;
open HD,'/etc/resolv.conf' or die $!;
print <HD>;
close HD;
}
print "\n";
print <HD>;
close HD;
__END__
You open another HD in a block but wouldn't close the before opened
HD,so you can print both files' content.
Otherwise if you don't use a local, the before HD was closed and
re-opened, you lost the first file-handle,which is maybe dangerious in
large project.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/