in reply to reset function

Of course just because it's clumsy, buggy, error prone, and just plain stupid, doesn't mean it's impossible:

use strict; use warnings; our $var = 10; our $keep = 20; print "\$var = $var\n"; print "\$keep = $keep\n"; print "Reset <<\$$_>>\n" for dangerous_reset(qr/^v/); print "\$var = $var\n"; print "\$keep = $keep\n"; sub dangerous_reset { my $criteria = shift; my $package = (caller)[0] . '::'; { no strict 'refs'; my @wanted = grep { /$criteria/ # Meets cr +iteria && defined *{$package . $_}{SCALAR} # Has scal +ar element && /^[\p{alpha}_]\w*$/ # Isn't sp +ecial. } keys %{$package}; undef ${*{$package . $_}{SCALAR}} for @wanted; return @wanted; # Return count, or list of variables removed. } }

We had a troll here a few years ago who kept pushing some strategy he had for resetting variables programatically. I'm sure his kludge was a lot better thought out than the code I've shown here, but it was still a terrible, bug-prone, broken sledge-hammer of a tool. It's just not how things should be done.


Dave