in reply to Re^2: How to tell methods exist in a package
in thread How to tell methods exist in a package

What if the package is; $val = "FOO" ;
This doesn't work: if (exists &$val::mySub) {...}

Thanks
Luca
  • Comment on Re^3: How to tell methods exist in a package

Replies are listed 'Best First'.
Re^4: How to tell methods exist in a package
by tirwhan (Abbot) on Nov 21, 2005 at 17:50 UTC

    No, but this does:

    $val="FOO"; $method="${val}::mySub"; if (exists &$method) {...}

    Also,

    if ($val->can("mySub")) { ... }

    works (with the aforementiond behavioural differences of course).


    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
      very nice!!!, I prefer the one with can(..)!!

      Cheers
      Luca