Scarborough has asked for the wisdom of the Perl Monks concerning the following question:
I'm currently working using an eval to capture errors in subroutines and this is a very slimmed down version of what i'm doing
#use strict; use vars qw($AUTOLOAD); &mysub_('foo','bar'); sub mysub{ #do something... print "in mysub\n"; return; } sub AUTOLOAD{ my @args = @_; $AUTOLOAD =~ /.*::(.*)_/ my $sub_name = $1; #no strict 'refs'; eval{&$sub_name(@args)}; #use strict 'refs'; print @; #do something with $@ to check runtime errors }
With strict commented out it works exactly as I had hoped but with strict back in $@ contains the messaage
Cant use string ("mysub") as sub routine ref while strict refs in use
I've got round it with turning strict refs on and off (commented out at the moment) but I'm not sure if this is a good way of dealing with the problem.Any ideas
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strict and runtime sub names
by ysth (Canon) on Sep 10, 2004 at 10:26 UTC | |
|
Re: Strict and runtime sub names
by broquaint (Abbot) on Sep 10, 2004 at 11:43 UTC |