Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: C pre-processor in Perl

by Rhandom (Curate)
on Jul 28, 2003 at 19:24 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-19 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found