[tpm] Filehandle $fh opened only for output at ....
zoffix at zoffix.com
zoffix at zoffix.com
Wed May 3 14:21:29 PDT 2017
Quoting Shlomi Fish <shlomif at shlomifish.org>:
> Hi Zoffix and Tom!
\o Didn't expect you to follow Toronto's list :)
>>> As I recall the idiom is `while (defined(my $foo = <$fh>))`
I think I sidetracked the discussion with that comment :)
I highly doubt the `defined` is the cause of the issue or that perl
would be lying about the handle not being opened for writing. Likely
the handle is re-opened by some adjacent code or file handle's
variable accidentally reused in another open, like passed via a sub,
for example.
$ perl -we 'open my $fh, "<", "foo"; open $fh, ">", "foo"; <$fh>'
Filehandle $fh opened only for output at -e line 1.
$ perl -we 'sub foo { open $_[0], ">", "foo"; }; open my $fh,
"<", "foo"; foo $fh; <$fh>'
Filehandle $fh opened only for output at -e line 1.
Perhaps the OP can provide a larger piece of code; something that
traces the life of $fh.
More information about the toronto-pm
mailing list