No such thing as a small change | |
PerlMonks |
Lexical filehandles: unblessed but (sometimes) canby vr (Curate) |
on Mar 15, 2018 at 13:08 UTC ( [id://1210949]=perlquestion: print w/replies, xml ) | Need Help?? |
vr has asked for the wisdom of the Perl Monks concerning the following question: (s/lexical filehandles/references to autovivified anonymous filehandles/ig;) There are some (minor) annoying inconsistencies:
In case of "print", indirect & direct method invocations obviously compile differently (+ see below), with different side effects, but:
And:
It's unclear why lexical filehandle can not do its methods from the start, and for what it was made able "to can" after some magic passes. Why bother with waiting to attach this black magic until later (or at all), and not bless poor things to e.g. IO::Handle class, so that they officially can? Performance/resources issue? But, it looks like e.g. autoflushing on one lexical filehandle results to (costly?) black magic turned on all over the program, in different scopes and packages. If so, it somehow reminds of penalties of using $`, $&, $' in previous days.
Why do I care? :) Just curious, and also yesterday I was playing with Log::Dispatch::Handle: Basically, anything that implements a print() method can be passed the object constructor and it should work. So I tried first:
Using my "secret weapon" autoflush $fh 1; after open:
How very bizarre. I must admit, with more recent Perl and Log::*** and dependencies installed, the error message makes more sense:
So, of course I did
and everything works. But, all of the above leaves impression of unclear purposes and behaviour, and possible troubles ahead, for unwary :).
Back to
Seekers of Perl Wisdom
|
|