http://www.perlmonks.org?node_id=435620


in reply to Re: Perl oddities
in thread Perl oddities

I had never really thought of it like that: maybe because we teach it in the second day of Learning Perl and I don't talk about objects and such then. This has also been around a bit longer than

Too bad this doesn't seem to work.

#!/usr/bin/perl STDOUT->print( "Hello World!\n" );

I get this error:

Can't locate object method "print" via package "IO::Handle" at io.pl l +ine 3.

If I change it slightly, though, I get the expected output. I'm surprised I didn't get the "perhaps you forgot to load ..." message that usually comes with this sort of error.

#!/usr/bin/perl use IO::Handle; STDOUT->print( "Hello World!\n" );
--
brian d foy <bdfoy@cpan.org>

Replies are listed 'Best First'.
Re^3: Perl oddities
by ikegami (Patriarch) on Mar 01, 2005 at 22:24 UTC
    I'm surprised I didn't get the "perhaps you forgot to load ..." message that usually comes with this sort of error.

    Odd, I get the message...

    >perl -e "bless({}, 'Cow')->moo();" Can't locate object method "moo" via package "Cow" (perhaps you forgot + to load "Cow"?) at -e line 1. >perl -e "STDOUT->print();" Can't locate object method "print" via package "IO::Handle" (perhaps y +ou forgot to load "IO::Handle"?) at -e line 1. >perl -v This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2001, Larry Wall Binary build 633 provided by ActiveState Corp. http://www.ActiveState. +com Built 21:33:05 Jun 17 2002