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

Re: Include Constants from other files

by Chmrr (Vicar)
on Nov 13, 2002 at 07:31 UTC ( #212511=note: print w/ replies, xml ) Need Help??


in reply to Include Constants from other files

This is because of the way that use constant does its stuff -- it creates subroutines with empty prototypes in the current package. Here's one way to make it work; put the following lines in a file called Consts.pm:

package Consts; use constant PI => 3; # We're REALLY approximate, here. "Some true value as the last statement.";

In your main perl file (say, test.pl or somesuch) we'd say:

#!/usr/bin/perl -w use strict; use Consts; print "Pi is:", Consts::PI, $\;

See perldoc constant for more information -- there's a section which describes exactly this (search for the word "package")

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'


Comment on Re: Include Constants from other files
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2015-07-03 11:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (51 votes), past polls