in reply to Calling subroutine from other module
Having the *.pm files myblib and vlog
package myblib; sub foo { print +(caller(0))[3],"(@_)\n" } 1;
here are various flavours of calls:package vlog; use myblib; sub bar { print +(caller(0))[3],"(@_)\n" } 1;
# line 1 gen.pl use vlog; myblib::foo(1); myblib->foo(2); # foo(); # this would die - no foo() in main:: # bar(); # as would this package myblib; # temporarily switch package foo(3); package main; # switch back @ISA = qw(myblib); $a = bless do { \ my $x }, 'main'; $a->foo(4); # method lookup finds foo() in myblib:: # shoehorn the foo() function into main:: - that's roughly # what Exporter and 'use myblib qw(foo)' do *foo = *myblib::foo; foo(5); # now found in main:: $a->foo(6); __END__ myblib::foo(1) myblib::foo(myblib 2) myblib::foo(3) myblib::foo(main=SCALAR(0x818c688) 4) myblib::foo(5) myblib::foo(main=SCALAR(0x818c688) 6)
--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}
|
|---|