in reply to C pre-processor in Perl

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)];

Replies are listed 'Best First'.
Re: Re: C pre-processor in Perl
by perrin (Chancellor) on Jul 28, 2003 at 19:43 UTC
    I would use globals for that, since they don't get messed up by use in a quoted context.

    BEGIN { use vars qw($FOO); $FOO = ... # some slow action here } if ($FOO) { }