Why does Programming Perl use local (not my) for filehandles?
问题 When I read through Programming Perl , 2nd Edition, Page 51, something confuses me : sub newopen { my $path = shift; local *FH; #not my! open (FH, $path) || return undef; return *FH; } $fh = newopen('/etc/passwd'); My I know, why we are not recommenced to use my? So far, I cannot see anything will go wrong if we use my(). Thanks! 回答1: The trite answer is that you have to use local because my *FH is a syntax error. The "right" (but not very enlightening) answer is that you're doing it wrong.