in reply to Here's a quick example why not to use Indirect notation
in thread Perl High School

By using indirect notation, you're removing the capability for the interpreter to spellcheck you if you have defined a new function in the current package.

I find this less than compelling, perhaps because I always use parenthesis on method or function calls.   my $bar = new FOO(); isn't going to be tripped up by having written a new routine in the current package. Consider

package FOO; sub new { print "right!\n"; } package BAR; sub new { print "wrong!\n"; } my $f = new FOO(); # prints "right!"
Update: hold on, my $f = new FOO;    # also prints "right!" Where's the problem?

Replies are listed 'Best First'.
Re: Re: Here's a quick example why not to use Indirect notation
by dragonchild (Archbishop) on Feb 22, 2002 at 18:08 UTC
    Interesting! Anyone want to explain why this works??

    However, the syntax looks horrible. You have parentheses, indicating a function or method name, on a token indicating a package name. This looks to be a very poor design decision, in my opinion.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      However, the syntax looks horrible. You have parentheses, indicating a function or method name, on a token indicating a package name. This looks to be a very poor design decision, in my opinion.

      Try approaching this from the perspective of creating an instance of a Class, rather than invoking a method in a package. Perl doesn't have constructors, but you can simulate the effect. I do this for expressive purposes.

        In addition, if you mistype the name, so say you do something like:
        package Foo; sub new { return bless {}, shift; } -------- use Foo; my $bar = new FOO();
        You get an error saying that main::FOO() could not be found. That's not a good error.

        Direct notation is put there for a purpose. I think that indirect notation was a bad idea all around, put in to pander to another community that looks down on Perl usage to begin with. *shrugs*

        ------
        We are the carpenters and bricklayers of the Information Age.

        Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.