http://qs321.pair.com?node_id=1230733


in reply to Re^5: accessing stashes
in thread accessing stashes

I know that.

But I want one expression to determine the condition, I want to avoid (for reasons of pure idiocy) to have an extra assignment...

So something like

print defined *main::{$symbol}->*{CODE} ? "yep": "nope";
But I cannot do it...

Replies are listed 'Best First'.
Re^7: accessing stashes
by ikegami (Patriarch) on Mar 01, 2019 at 19:55 UTC

    It's $glob && *$glob{CODE}, not defined *main::{$symbol}->*{CODE}.

      First of all thanks a lot for solving my problem.

      But I was wondering if there is an expression that would avoid having a two-step solution (i.e. without first assigning a temporary $glob variable).

      So is there an expression that when I have a symbol ("hubba" say) I could do a

      $some_convoluted_expression{hubba}->{CODE}
      (or something like that) to determine whether or not there is a sub-routine of that name in the main-package.

      But this is for bonus-points only...

        You can't check if the glob contains a code reference before you make sure you have a glob in the first place!

        But this is all moot. This solution doesn't work as of Perl 5.22. You should be using one of the solutions that work in 5.22 and beyond. See Re^4: accessing stashes