Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How to alias a whole namespace to another namespace (in this case main::)

by simonm (Vicar)
on Nov 15, 2004 at 05:01 UTC ( #407771=note: print w/replies, xml ) Need Help??


in reply to How to alias a whole namespace to another namespace (in this case main::)

This should work:
no strict refs; *{$target_package . "::"} = *{$source_package . "::"};

For example:

*{"main::"} = *{"foo::"};

Replies are listed 'Best First'.
Re^2: How to alias a whole namespace to another namespace (in this case main::)
by aufflick (Deacon) on Nov 15, 2004 at 05:18 UTC
    sub foo::bar {print "bar\n"} *{"main::"} = *{"foo::"}; bar();

    Results in:

    Modification of a read-only value attempted at - line 2.

    And I want to add to main, not completely replace it.

      Modification of a read-only value attempted

      Sorry, I'd never tried aliasing over main that way; I guess the root package name is more special than the others.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2021-10-26 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (90 votes). Check out past polls.

    Notices?