in reply to mod_perl with Apache::Registry with CGI.pm design considerations
Now you will never be able to change the value of $foo for that bar() sub.my $foo = $query->param('foo'); bar(); sub bar { print $foo; }
It's easy to prevent this. You can pass the values to your subs:
In addition to avoiding closures, it's simply a better programming practice. it improves abstraction and makes your code more robust. You could also put your subs in a separate module (a real module with a package name, not just a "require lib.pl" thing), which would force you to pass values to your subs.my $foo = $query->param('foo'); bar($foo); sub bar { my $foo = shift; print $foo; }
|
|---|