March 2002 | Perl Hardware Store | 14 |
Now we'll see how use constant works
sub import { my $name = shift or return; my $value = shift;
my $caller = caller; *{$caller . "::$name"} = sub () { $value }; }
The caller can say
use constant PI => 3;
$circumference = 2 * PI * $r;
Real module has error checking, list constants, etc.
Real module also loads 1289 lines of code!
(Up 18% since 1998)
Next | Copyright © 2002 M-J. Dominus |