Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Dynamic Package Name & Subroutine Call

by awohld (Hermit)
on Dec 14, 2012 at 22:32 UTC ( [id://1008908]=note: print w/replies, xml ) Need Help??


in reply to Dynamic Package Name & Subroutine Call

By George, I think I just figured it out:

CHANGE:
Test::$pkg::hello($pkg);
TO:
{ no strict 'refs'; &{"Test::" . $pkg. "::hello"}($pkg); }

Replies are listed 'Best First'.
Re^2: Dynamic Package Name & Subroutine Call
by ikegami (Patriarch) on Dec 16, 2012 at 13:55 UTC
    The following works with strict on:
    (\&{"Test::${pkg}::hello"})->($pkg);
    The same, but more readable:
    my $sub = \&{"Test::${pkg}::hello"}; $sub->($pkg);

    Then again, explicitly using no strict 'refs'; might be better a good thing.

    That said, it looks like you have a method call (to which you're passing the wrong package name). If so, you should be using

    ("Test::".$pkg)->hello(...);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1008908]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found