Andrew Pimlott wrote:
> sub foo
> {
> my ($x, $y, $z) = @_;
> sub helper
> {
> ... $x $y $z ...
> }
> ...
> ... helper() ...
> ... helper() ...
> ...
> }
>
> In Perl 5 you can get around this by assigning
> an anon sub to a glob ref (ugh)
hm, well, you can get around glob refs as shown
below. (haven't checked for typos, etc)
#!/user/local/bin/perl
use Symbol::Table;
my $symbol=Symbol::Table->new('CODE');
sub foo
{
my ($x,$y,$z)[EMAIL PROTECTED];
# Look Ma! No typeglobs!
$symbol->{helper}=sub
{
$x++;$y+=2;$z*=2;
}
helper();
helper();
}
Symbol::Table is a module I just released to CPAN
expressly for fiddling with the symbol table
without the user having to do eval() or fiddle
with *type_globs. all that nastyness is hidden
in the module. $symbol is a reference to a tied
hash, the keys are the names of the symbols,
the values are references to the symbols.
make sure you get Symbol-Table-1.01.tar.gz
SymbolTable-* is scheduled for deletion.
Oh, just a warning, read the POD, but dont
look at the code in the module, it's the
work of a madman. ;)
Enjoy,
Greg London
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm