Answer to udpated question:
When used as a file handle:
- Pro: Lexicals can't be localized (but they can be block scoped).
- Con: Typeglobs can't be blocked scoped (but they can be localized).
- Pro: open LEXICAL, ... requires 5.6 or greater.
- Con: The name isn't checked at run-time, so typos are harder to find. However, you will get a compile-time warning if the typo isn't repeated or pasted. For example,
perl -Mstrict -w -e "my $fh = *STDOOUT; print $fh 'moo'"
When used as a tied file handle:
- I think you have no choice but to use a typeglob if you want a tied file handle.
When used to alias function:
- There's no other way without using eval EXPR.
When used to alias other things: