Hi Ynon.
> I recently tried some symbol table manipulations and encountered the
> following:
>
> This code works:
> $main::{foo} = sub { warn 'M::Foo' };
> foo();
>
> But this one doesn't:
> BEGIN {
> $main::{foo} = sub { warn 'M::Foo' };
> }
> foo();
>
Weird indeed. but why do you use '$' before main? I don't understand why
the first example works at all.
As I read it, you are assigning a code ref to the scalar $main::foo. why
calling to foo() afterwards works?
If I'd write this code, it will be:
BEGIN {
no strict 'refs';
*{"main::foo"} = sub { warn 'M::Foo' };
}
foo();
(and it works)
Shmuel.
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl