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,
*main:: = *my_temp_convert::;
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?

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
    Hash slicing will surely do the job. But what I'm talking about is a single line normal assignment, like what I am sure I did in the past. Just like we do with individual symbols,
    *alias = *target; # so we have $alias = $target, @alias = @target # %alias = %target and so on
    but we can do it package-wise.
    Assigning the symbol table hash itself doesn't help either (because it clobbers the table)
    You are right, shmem. I really forget how I did what I'm trying to say, but I really did. So, until I find my old code, I will consider that it can't be done, and stick with the for loop or hash slicing as shmem shown for this particular task.

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!