[Israel.pm] Importing variable

Shlomi Fish shlomif at iglu.org.il
Tue Aug 31 03:03:29 PDT 2010

Hi Dov,

On Tuesday 31 August 2010 12:47:10 Levenglick Dov-RM07994 wrote:
> Hi,
> Although this is bound to be the oldest question in the book, how do I
> perform the C equivalent of #include "defines.h" in Perl 5.12
> I want to have a separate file that will define variables accessible to
> all parts of my script. If it makes the answer any easier, they can
> become environment variables (i.e. inserted into %ENV).

You can define package-scope variables using something like:

# Define a variable:

our $pi = 3.141592;
our $num_days_in_year = 365;

# And then wherever:

sub hello
	my $r = shift;

	print "You have a circle with a circumeference of ", (2 * $::pi * $r), 


Even modules (that can be loaded using "use", "require", etc.) can define such 
package scope variables.


	Shlomi Fish

> Best Regards,
> Dov Levenglick
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl

Shlomi Fish       http://www.shlomifish.org/
Why I Love Perl - http://shlom.in/joy-of-perl

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

More information about the Perl mailing list