in reply to Re: multiple "sub" packages in 1 file: possible? how?
in thread multiple "sub" packages in 1 file: possible? how?
Note: I remember I once used a single assignment to basically do the same with what for does above, but I can't find references about that in the official docs anymore. The assignment below,gives me a "Modification of a read-only value" fatal exception. I'm not sure if that's the correct syntax I used or thing has changed. Any monk knows what happens?*main:: = *my_temp_convert::;
What happens is just what you noticed. The symbol table typeglob itself is read-only. Assigning the symbol table hash itself doesn't help either (because it clobbers the table):
package foo; sub foo {print "bar"}; package main; %main:: = %foo::; print "$_ => $main::{$_}" for keys %main::; foo(); __END__ foo => *foo::foo Undefined subroutine &main::foo called at -e line 1.
so the shortest way to do the assignment you want is using a "hash slice":
@main::{ keys %foo:: } = values %foo::;
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: multiple "sub" packages in 1 file: possible? how?
by naikonta (Curate) on Aug 08, 2007 at 01:28 UTC |