in reply to Re^2: Defining a function in the caller's package
in thread Defining a function in the caller's package

Don't do that. You're assigning a sub in Foo to return the results of a call made to ForeignModule. Then you're setting main::do_something to be the same as that subroutine. What you actually want is not to return the value but to make main::do_something the very same sub as ForeignModule::NEXT.
package ForeignModule; sub NEXT { print scalar caller } 1;
package Foo; # there is no do_something sub import { my $target = caller; no strict 'refs'; *{"$target:\:do_something"} = \&ForeignModule::NEXT; } 1;
package main; use strict; use warnings; use Foo; do_something();

Replies are listed 'Best First'.
Re^4: Defining a function in the caller's package
by rovf (Priest) on Aug 12, 2008 at 08:19 UTC
    Thanks a lot for the clarification!