subroutine exists

Discussion in 'Perl Misc' started by George Mpouras, Mar 27, 2012.

  1. How can I find if a subroutine exists without try to call it ?
    George Mpouras, Mar 27, 2012
    #1
    1. Advertising

  2. I think I found it


    my $var = 'f2';
    print ref *{__PACKAGE__.::.$var}{CODE} ;
    George Mpouras, Mar 28, 2012
    #2
    1. Advertising

  3. I have to check if an external package have a method or not (windows ,
    linux)
    George Mpouras, Mar 28, 2012
    #3
  4. "George Mpouras" <>
    writes:
    > I have to check if an external package have a method or not (windows
    > , linux)


    That a symbol table entry pointing at a code reference exists at the
    moment doesn't necessarily mean it will still exist by the time it is
    supposed to be used and vice-versa. In particular, this check won't
    find anything an AUTOLOAD sub will either create or emulate.
    Rainer Weikusat, Mar 28, 2012
    #4
  5. correct. It is a little bit more complicated. I know that my methods exists,
    but they should not try to call something that do not exist, autoload
    automation does not help a alot

    Ο "Rainer Weikusat" έγÏαψε στο μήνυμα
    news:...

    "George Mpouras" <>
    writes:
    > I have to check if an external package have a method or not (windows
    > , linux)


    That a symbol table entry pointing at a code reference exists at the
    moment doesn't necessarily mean it will still exist by the time it is
    supposed to be used and vice-versa. In particular, this check won't
    find anything an AUTOLOAD sub will either create or emulate.
    George Mpouras, Mar 28, 2012
    #5
  6. Some::package->can("some_method") is good. The side effect is that executes
    the method (if exists) when you might only want to check
    George Mpouras, Mar 28, 2012
    #6
  7. Am 28.03.2012 10:19, schrieb George Mpouras:
    > Some::package->can("some_method") is good. The side effect is that executes
    > the method (if exists) when you might only want to check


    I don't observe such a side effect. It doesn't execute the function.

    from perltoot:
    The can() method, called against that object or class, reports back
    whether its string argument is a callable method name in that class. In
    fact, it gives you back a function reference to that method:

    - Wolf
    Wolf Behrenhoff, Mar 28, 2012
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Casey
    Replies:
    3
    Views:
    853
    Casey
    Jan 30, 2004
  2. Hon Seng Phuah
    Replies:
    1
    Views:
    478
    Jürgen Exner
    Mar 5, 2004
  3. Totan
    Replies:
    0
    Views:
    939
    Totan
    Apr 17, 2006
  4. Ulf Meinhardt
    Replies:
    8
    Views:
    6,144
  5. king
    Replies:
    5
    Views:
    185
Loading...

Share This Page