in reply to Filehandles vs. Packages: And the winner is...

It doesn't give as specific of guidance as you might expect, but search for the word WARNING in perlobj. It makes it very clear that the indirect object notation is ambiguous.

This is why Damian Conway says in his book that you should avoid the indirect object notation...

UPDATE
As came out several levels below, I had not understood the error at all. It is far more subtle...

  • Comment on Re (tilly) 1: Filehandles vs. Packages: And the winner is...

Replies are listed 'Best First'.
Re: Re (tilly) 1: Filehandles vs. Packages: And the winner is...
by blakem (Monsignor) on Aug 30, 2001 at 03:44 UTC
    In other words, the ambiguity is removed if written like so:

    perl -MCGI -e 'my $q = CGI::new(); open CGI, "~/foo.txt";'

    -Blake

      Um, you would want to write:
      my $q = CGI->new();
      Otherwise you have coded a function call, not a method lookup, which means that it is missing its first argument and won't know to search the inheritance hierarchy (if any) looking for the method.

        The arrow invocation produces the same result in this case:

        $ perl -MCGI -e 'my $q = CGI->new(); open CGI, "~/foo.txt"; print ref +$q;' Can't locate object method "new" via package "IO::Handle" (perhaps you + forgot to load "IO::Handle"?) at -e line 1.

        conv

        Yeah exactly. This can be seen below....
        package Snafu; use Carp 'cluck'; sub new { warn join ',',@_; } 1; Snafu::new("Test"); Snafu->new("Test");
        although the following is also interesting
        package Snafu; use Carp 'cluck'; sub new { cluck join ',',@_; } sub _new { goto &new } 1; Snafu::new("Test"); Snafu->new("Test"); Snafu->_new("test");
        I tried that originally, and it still collided with the filehandle....

        perl -MCGI -e 'my $q = CGI->new(); open CGI, "~/foo.txt";' Can't locate object method "new" via package "IO::Handle" at -e line 1 +.

        -Blake