guiwp has asked for the wisdom of the Perl Monks concerning the following question:
To use FILEHANDLE alone to print the content of $_ to it, you must use a bareword filehandle like FH, not an indirect one like $fh
I saw some websites saying that BAREWORDS to refer file handles are dangerous because they are global. But now here I see they "prohibiting" it when you like a syntax sugar. Just don't get it...
Is there any other context where automatic use of $_ can't be applyed?
I mean, if I want to print the current $_ to another file handle (not STD{OUT,ERR, etc.) I can't omit $_:
while(<>){ print $fh; #doesn't work print $fh $_; #work }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Where automatic variable $_ doesn't work?
by choroba (Cardinal) on Jul 04, 2016 at 19:58 UTC | |
by GrandFather (Saint) on Jul 04, 2016 at 20:55 UTC | |
by choroba (Cardinal) on Jul 04, 2016 at 21:12 UTC | |
by guiwp (Sexton) on Jul 04, 2016 at 20:27 UTC | |
|
Re: Where automatic variable $_ doesn't work?
by haukex (Archbishop) on Jul 04, 2016 at 20:04 UTC | |
by guiwp (Sexton) on Jul 04, 2016 at 20:23 UTC |