[Israel.pm] Importing variable

Levenglick Dov-RM07994 RM07994 at freescale.com
Tue Aug 31 03:42:33 PDT 2010


I am looking for a solution that allows the package scope variables to
be defined in a different file

 
Best Regards,
Dov Levenglick
SmartDSP OS Development Leader

-----Original Message-----
From: Shlomi Fish [mailto:shlomif at iglu.org.il] 
Sent: Tuesday, August 31, 2010 13:03
To: perl at perl.org.il
Cc: Levenglick Dov-RM07994
Subject: Re: [Israel.pm] Importing variable

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:

[code]
# 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), 
"\n";
}

[/code]

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

Regards,

	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