Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: C pre-processor in Perl

by Rhandom (Curate)
on Jul 28, 2003 at 19:24 UTC ( #278579=note: print w/replies, xml ) Need Help??

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) { }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://278579]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2021-05-15 02:48 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (150 votes). Check out past polls.