roho has asked for the wisdom of the Perl Monks concerning the following question:
Since bareword filehandles are due to be deprecated, this may not be a pressing issue. I'm posting this so that others who may run into the same situation do not have to spend the debugging time tracking down this inconsistency.
The following code shows the inconsistency:
#!/usr/bin/perl use strict; use warnings; my $HFILE; my $hfile = 'foo.txt'; # GOOD ##################################################################### # Bareword filehandle works with space following heredoc "<<". ##################################################################### open(HFILE, '>', $hfile) or die "Error opening help file $hfile: $!\n" +; print HFILE << "EOT"; Usage: foo.pl Options: -------- -h Display help information. EOT # BAD ##################################################################### # Lexical filehandle does NOT work with space following heredoc "<<". ##################################################################### open($HFILE, '>', $hfile) or die "Error opening help file $hfile: $!\n +"; print $HFILE << "EOT"; Usage: foo.pl Options: -------- -h Display help information. EOT
"It's not how hard you work, it's how much you get done."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Heredoc Inconsistency: Bareword Filehandle vs Lexical Filehandle
by haukex (Archbishop) on Jun 09, 2022 at 19:55 UTC | |
by LanX (Saint) on Jun 09, 2022 at 20:35 UTC |