in reply to Is it possible to create a sub exclusive to a sub?

One could implement something using the caller builtin, i.e. :-
use strict; &foo; &badfoo; sub foo { &bar; } sub badfoo { &bar; } sub bar { if ((caller(1))[3] ne 'main::foo') { die((caller(0))[3], ": can not be called from ", (caller(1))[3], " due to restrictions"); } print "called sub ",(caller(0))[3], "\n"; }
Update: changed "print STDERR" to "die"

Replies are listed 'Best First'.
Re^2: Is it possible to create a sub exclusive to a sub?
by ihb (Deacon) on Sep 19, 2004 at 10:42 UTC

    I think you indeed missed the point a bit. The idea isn't to prohibit people from calling it (althought you do by using the other solutions too). The idea is mainly to not pollute the global namespace.

    ihb

    Read argumentation in its context!