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


in reply to Perl oddities

print FH @list is not unique. It's called the "indirect object" method invocation syntax. The example in perlobj is new Critter ('Barney', 1.5, 70). True, FH is not (necessarily) an object here, but it behaves just like one.

Replies are listed 'Best First'.
Re^2: Perl oddities
by brian_d_foy (Abbot) on Mar 01, 2005 at 21:26 UTC

    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>
      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