Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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
Re: Typeglob syntax arcanery
by Anonymous Monk on Mar 03, 2011 at 18:14 UTC
    AND without using eval
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 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.

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 studying the Monastery: (11)
As of 2014-08-28 14:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (263 votes), past polls