Hello mighty monks, here is something strange I encountered today:
MyModule.pm :Importer.pm :package MyModule; use Importer; 1;
package Importer; sub import { my $caller = caller; print $caller . "\n"; } 1;
and the last piece, test.pl :
use strict; no strict 'refs'; my $symtab = *{'main::MyModule::'}{HASH}; require 'MyModule.pm'; 1;
When I start test.pl, as shown above, the result is:
main::MyModule
so this is the caller. But if you slightly modify it either by removing
or by changingmy $symtab = *{'main::MyModule::'}{HASH};
torequire 'MyModule.pm';
require MyModule;
the result is just (as expected) MyModule.
I tested it on the latest version of perl (5.18.1), as well on version 5.10.1. Results are the same.
Why this inconsistency happens? It caused me a lot of trouble and for me it looks suspicious.
Thanks.
In reply to Strange side effect on 'caller' function result by ainkov
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |