[Q] package "IO::Handle"

B

bill

If I try STDOUT->foo("bar") in the debugger I get:

DB<1> STDOUT->foo("bar")
Can't locate object method "foo" via package "IO::Handle" (perhaps you forgot to load "IO::Handle"?) at (eval 25)[/usr/share/perl/5.6.1/perl5db.pl:1521] line 2.

....but

DB<2> p ref STDOUT

DB<3> p ref *STDOUT

DB<4>

How come Perl treats STDOUT as an IO::Handle object in <1>, but
ref does not report any class in <2> or <3>?

TIA,

-bill
 
S

Steve Grazzini

bill said:
DB<1> STDOUT->foo("bar")
Can't locate object method "foo" via package "IO::Handle" [...]
DB<2> p ref STDOUT

DB<3> p ref *STDOUT

DB<4>

How come Perl treats STDOUT as an IO::Handle object in <1>, but
ref does not report any class in <2> or <3>?

Long story short, the object is in the IO slot of *STDOUT.

print ref *STDOUT{IO};

You were looking at the string "STDOUT" and the glob *STDOUT,
neither of which are references.

Truth is, this is also a bareword string:

STDOUT->foo();

But during the method call Perl does some DWIMery to figure out
whether the string is supposed to be the name of a package or of
a filehandle.

Note the quotes:

% perl -e '"STDOUT"->foo'
Can't locate object method "foo" via package "IO::Handle"...

And the package:

% perl -e 'local STDOUT; STDOUT->foo'
Can't locate object method "foo" via package "STDOUT"...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,058
Members
48,769
Latest member
Clifft

Latest Threads

Top