I agree with
perrin on the
require portion. However - on the
constant portion - I have used schemes similar to the following many times:
use constant foo => do {
my $foo;
# do something that is really hard to lookup or calculate
$foo; # return of the do
};
This way, say you are in a daemon, or long running process, or mod_perl, and so on - you can get the compile time benefits, even with something that might take a minute or so to calculate the first time. It doesn't fit all situations - but for those it does it is nice to do a Deparse and see chunks of code removed when doing a
if (foo) {
} else {
}
my @a=qw(random brilliant braindead); print $a[rand(@a)];