David Coppit (via RT) wrote: > > When running the following script, > > use Symbol; > > require Storable; > Symbol::delete_package('Storable'); > > # Delete everything just to be safe. > map { delete $INC{$_} } keys %INC; > > require Storable; > Storable::freeze([1,2,3]); > > I get the following error: > > Undefined subroutine &Storable::freeze called at test.pl line 12. > > I was expecting the freeze function to be available after require'ing > Storable the second time. (i.e. no error) I will try to explain what I think is happening here with a simpler example : Let x.pl contain : use Symbol; Symbol::delete_package('A'); require A; A::foo(); And A.pm defining a single subroutine : package A; sub foo {print "foo\n"} 1; When x.pl is compiled, the %A:: stash is created to put an empty placeholder for the foo() subroutine, at compile time. This placeholder is supposed to be replaced by the actual subroutine when A is loaded (at runtime, since we use "require A".) However the placeholder is wiped out by delete_package(), and loading A.pm recreates a new A stash, but not necessarily with A::foo at the same memory address. And the original A::foo() call in x.pl has already been optimized to a glob pointer, since perl is smart enough to avoid a stash lookup each time it calls a subroutine. This glob has been undefined by delete_package(). And indeed, changing the A::foo() call to &{"A::foo"}(); makes it work, because this forces the symbolic lookup. I don't know how to fix this.