in reply to Bareword vs. Indirect Filehandle behaviour
is just relying on yet another perl Do-What-I-Mean feature. The bareword OUT happens to be a filehandle, and the statement resolves to a bare print statement (to that filehandle). A bare print results in printing $_.print OUT;
In fact, a bareword after print is always interpreted as a filehandle1, no matter if it exists:
With indirect filehandles that isn't the case: here the filehandle is a scalar holding a reference to a glob. Perl can't figure out what you mean (and imho ought not, anyways), so your variable's content gets printed. Only with print $expr LIST inspection of $expr is done.$ perl -wle 'print OUT' Name "main::OUT" used only once: possible typo at -e line 1. print() on unopened filehandle OUT at -e line 1.
<update>
$ perl -wle 'print $fh' Name "main::fh" used only once: possible typo at -e line 1. Use of uninitialized value in print at -e line 1. $ perl -wle 'print $fh $bar' Name "main::bar" used only once: possible typo at -e line 1. Name "main::fh" used only once: possible typo at -e line 1. Can't use an undefined value as a symbol reference at -e line 1.
Only in the latter case perl tries to resolve $fh to a filehandle.
1) unless your bareword is a constant as in
</update>
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Bareword vs. Indirect Filehandle behaviour
by johngg (Canon) on Sep 19, 2006 at 10:37 UTC | |
by rodion (Chaplain) on Sep 19, 2006 at 10:57 UTC | |
by chromatic (Archbishop) on Sep 19, 2006 at 17:01 UTC | |
by johngg (Canon) on Sep 19, 2006 at 11:04 UTC |