in reply to Re^2: what does the retval of can() do ?
in thread what does the retval of can() do ?

You can dereference it (and call it). What did you expect?

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
  • Comment on Re^3: what does the retval of can() do ?

Replies are listed 'Best First'.
Re^4: what does the retval of can() do ?
by Fletch (Bishop) on Feb 15, 2006 at 14:26 UTC

    A pony. Come on, it's obvious.

    WHERE'S MY PONY?

    /sob

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^4: what does the retval of can() do ?
by blazar (Canon) on Feb 16, 2006 at 07:51 UTC

    Or pass it around. To have it dereferenced elsewhere.

    More seriously, I see that the OP is learning about a subject and discovering certain features. Now he's trying to understand what they really are to see if any of them can serve him right. So far, so fine: it's a learning model and I guess we all passed through it to some degree. OTOH unless one is really astonished about the particular feature under consideration, chances are that he will forget about it, but if the whole matter is turned around, i.e. if one has a task to accomplish and someone suggests a particular feature to do so, then most probably that will be the best way to really understand that particular feature's usefulness.

    So I would recommend the OP not to get mad about trying to understand everything and soon, but rather to wait to have an actual problem at hand and to discover which features are useful to deal with it.

Re^4: what does the retval of can() do ?
by Anonymous Monk on Feb 15, 2006 at 14:39 UTC
    Ok, I see, you can call it like:
    $a = A->new ; $b = $a->can('test') ; A->$b() if defined $b ; $b = undef ; # de-ref

    Thanks

      I suggest something more like:

      $a->$b() if defined $b;

      ... but whether your code is correct really depends on the implementation of the test() method. I usually see code that just checks whether can() returns a true value.