in reply to Beginnings of Online CGI Course

I don't know the answer to this, but I have heard from various sources that:
my $query = CGI->new();
is preferable to
my $query = new CGI;
I'm a bit curious as to why that would be preferable, so I open that topic up for discussion. If a good reason for it is revealed, Ovid, you might want to do it that way in your course. Of course, in the spirit of TIMTOWTDI, you could decide you like it the way you have it, and leave it that way.

Personally I always use the arrow method, but I don't know which one is "right".

Replies are listed 'Best First'.
Indirect object syntax (RE: Beginnings of Online CGI Course)
by tye (Sage) on Oct 06, 2000 at 22:10 UTC

    new CGI is easily misunderstood. Some even suggest that you should write CGI::->new() to prevent CGI->new() being interpretted as main::CGI()->new(), which is possible. I'm not completely decided on that last point because I don't think it is supported in moderately old versions of Perl and I feel that I can usually avoid having functions that have the same name as modules that I use. I will probably convert to CGI::->new() before too long, though.

    So let's consider:

    my $q= new CGI;
    What if you do this from a package? You probably have a new() method of your own and now you've (probably) done:
    my $q= new( "CGI" );
    I think there are also gotchas with regard to confusing precedence, but I don't recall them.

    So many (including me) suggest that you always avoid "indirect object" notation. This might also apply to the standard:

    print HANDLE "Stuff\n";
    which should instead be written:
    HANDLE->print( "Stuff\n" );
    but I've not seen that point pushed much. I personally think that things will slowly migrate that direction, though.

            - tye (but my friends call me "Tye")