in reply to Remove bless reference or class/package name from method arguments

For these particular examples, argument counting would be sufficient.

sub pow { shift if @_ > 2; return $_[0] ** $_[1]; }

If the number of arguments is unknown (e.g., sum), I do not know how (and do not believe that it is possible) to determine how the sub was invoked.

Good Day,
    Dean

  • Comment on Re: Remove bless reference or class/package name from method arguments
  • Download Code

Replies are listed 'Best First'.
Re^2: Remove bless reference or class/package name from method arguments
by ikegami (Patriarch) on May 20, 2009 at 14:48 UTC
    Or just
    sub pow { return $_[-2] ** $_[-1]; }

    Approaches that rely on the number of arguments rather than the type of arguments are going to be more resilient.

Re^2: Remove bless reference or class/package name from method arguments
by binf-jw (Monk) on May 20, 2009 at 10:38 UTC
    Thank you Dean,

    For most of the implementations I can use argument counting, infact I commonly pass multiple arguments as a HASH reference which kind of solves the problem. Variable size lists can even pass as an ARRAY reference:
    $obj->staticMethod( [ $arg1, $arg2, $arg3 ] );

    I was hoping there was some funky way of getting how it was invoked just for curiousity.

    John,