I would say that what you are doing is probably not a very good software design. If you need something from your caller, it's probably a better idea to have the caller pass it as an argument. That way, it's documented that the called routine is using it. Using backdoor methods such as this to get information from the caller leads to unmaintainable code. Make sure you document this behavior so that anyone that uses this code in the future knows their DATA handle is going to be used when they call this method.
With that said, if you really need to do it without modifying the calling code, try this.
sub called {
my $caller = (caller)[0];
my $fh = eval '\*'.$caller.'::DATA';
my $data = <$fh>;
print "read: $data\n";
}
|