Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Lexical filehandles: unblessed but (sometimes) can

by vr (Curate)
on Mar 15, 2018 at 21:02 UTC ( [id://1210998]=note: print w/replies, xml ) Need Help??


in reply to Re: Lexical filehandles: unblessed but (sometimes) can
in thread Lexical filehandles: unblessed but (sometimes) can

use strict; use warnings; use feature qw/ say /; use Scalar::Util qw/ blessed/; open my $fh, ">", undef; say blessed( *$fh{ IO }); # IO::File say *$fh{ IO }-> can( "print" ) ? "yes" : "no"; # no autoflush $fh 1; say *$fh{ IO }-> can( "print" ) ? "yes" : "no"; # yes

And:

use strict; use warnings; use Log::Log4perl qw / :easy /; use Log::Dispatch::Handle; open my $fh, ">", undef; #autoflush $fh 1; my $app = Log::Log4perl::Appender-> new( "Log::Dispatch::Handle", handle => *$fh{ IO }); __END__ The IO::File class is missing the 'print' method

And uncommenting the comment makes the program run OK and error message gone.

Replies are listed 'Best First'.
Re^3: Lexical filehandles: unblessed but (sometimes) can
by ikegami (Patriarch) on Mar 16, 2018 at 20:18 UTC

    That's because IO::File is loaded on demand. (One used to have to load it explicitly.) You can change the output to yes-yes by explicitly loading it.

      Simple answer to seemingly complex problem. Thank you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210998]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-24 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found