Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Typeglob syntax arcanery

by Anonymous Monk
on Mar 03, 2011 at 18:13 UTC ( #891274=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Here's what I want to do:
$pack1 = "alpha"; $sym1 = "beta"; $pack2 = "charlie"; $sym2 = "delta"; # insert magic here, that does this, without hardcoding the identifier +s # *alpha::beta = *charlie::delta
But I can't figure out the syntax. Help?

Comment on Typeglob syntax arcanery
Download Code
Replies are listed 'Best First'.
Re: Typeglob syntax arcanery
by BrowserUk (Pope) on Mar 03, 2011 at 18:32 UTC

    sub charlie::delta{ print "from:sub charlie::delta" };; $pack1 = "alpha"; $sym1 = "beta"; $pack2 = "charlie"; $sym2 = "delta";; *{ "$pack1\::$sym1" } = *{ "$pack2\::$sym2" };; alpha::beta();; from:sub charlie::delta

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Typeglob syntax arcanery
by Fletch (Chancellor) on Mar 03, 2011 at 18:29 UTC

    Erm . . .

    $ perl -le '$charlie::delta="foo";($a,$b,$c,$d)=qw( alpha beta charlie + delta ); *{"${a}::$b"} = *{"${c}::$d"};print $alpha::beta;' foo

    Wrap with a surrounding block of no strict as needed. Not that it's probably not a good idea to begin with.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Ahh, thanks. Perfect.
Re: Typeglob syntax arcanery
by Anonymous Monk on Mar 03, 2011 at 18:14 UTC
    AND without using eval

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://891274]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (15)
As of 2015-07-07 19:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls