in reply to Re: Variables in Common parent class
in thread Variables in Common parent class

Thanks! But one further question, why is there a dereferncing(->) operator while calling new on MyModule and scope resolution operator while calling new on SuperModule.

Replies are listed 'Best First'.
Re^3: Variables in Common parent class
by Athanasius (Archbishop) on Mar 11, 2013 at 03:18 UTC

    With the scope resolution operator, you get a normal subroutine call. But with the dereferencing operator, you get a method call in which the name of the class is passed implicitly as the first argument. So

    Foo::bar(1, 2, 3);

    calls sub bar in the Foo package and passes 1, 2, 3 as the arguments (which are aliased in @_). But

    Foo->bar(1, 2, 3);

    calls Foo::bar with the arguments Foo, 1, 2, 3. Likewise, if $obj is of class Foo, then

    $obj->bar(1, 2, 3);

    calls Foo::bar with the arguments Foo, 1, 2, 3.

    See Methods in perlootut and Method Invocation in perlobj.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,