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}
In reply to Re: Bareword vs. Indirect Filehandle behaviour
by shmem
in thread Bareword vs. Indirect Filehandle behaviour
by johngg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |