in reply to indirect object in camel book

What's happening is that the prototype tells Perl that main::new() accepts anything that might conceivably be a filehandle. The string 'CGI' certainly applies. Apparently this kind of thing is resolved before indirect method calls. (Makes sense to me, based on the locality principle.) Try, for example:

my $query3 = new STDIN;

Should that be a warning? I dunno. Is it a bug? I'm not sure. Seems like a good reason to avoid indirect object notation though, as well as prototypes. :)

Replies are listed 'Best First'.
Re: Re: indirect object in camel book
by astaines (Curate) on Oct 06, 2001 at 00:23 UTC

    Worse yet, it looks as if almost anything might conceivably be a file handle, like all of the following -->

    #!d:/perl/bin/perl -w use strict; use CGI; my $query=new CGI; sub new(*) { print "Ouch!!\n"} my $query2=new CGI; my $query3 = new STDIN; my $query4 = new $query; my $query5 = new query; my $query6 = new 1; my $query7 = new ""; my $query8 = new '';

    This also works -- (prints Ouch)

    my $query9 = new @;

    although the next line is not interpreted correctly.

    -- Anthony Staines