Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Newbie: Please me define global parameters (http://www.velocityreviews.com/forums/t892200-newbie-please-me-define-global-parameters.html)

mmasroorali@cse.buet.ac.bd 05-05-2005 02:35 AM

Newbie: Please me define global parameters
 
Hello All,
I want to keep some system parameters to be used by several
subroutines. So, I write in

ptestdefs.pm


#!/usr/bin/perl

# $Header:$
# $Log:$

use strict;
use warnings;

use Env;

# Column width for taskbar p columns
my $pw = "2.0mm";


Now in ptest.pl, I write

#!/usr/bin/perl

use strict;
use warnings;

use ptestdefs;

print "$pw\n";


When ptest.pl is executed, all I get is,

Global symbol "$pw" requires explicit package name at ./ptest.pl line
8.
Execution of ./ptest.pl aborted due to compilation errors.

Could you please tell me how I can define $pw in ptestdefs.pm to be
used in several other pm files?

Regards.


Tad McClellan 05-05-2005 02:53 AM

Re: Newbie: Please me define global parameters
 
mmasroorali@cse.buet.ac.bd <mmasroorali@cse.buet.ac.bd> wrote:


> Subject: Newbie: Please me define global parameters

^^^^^^

You shouldn't include that.

Have you seen the Posting Guidelines that are posted here frequently?


> I want to keep some system parameters to be used by several
> subroutines. So, I write in
>
> ptestdefs.pm



Lower case names are, by convention, reserved for pragmas.

You should choose a name with an Initial Capital.


> #!/usr/bin/perl


> use strict;


> my $pw = "2.0mm";



$pw is a "lexical variable", lexical variables are *never*
visible across file boundaries, for that you need a "package variable"
instead.


> Could you please tell me how I can define $pw in ptestdefs.pm to be
> used in several other pm files?



our $pw = "2.0mm";


See also:

"Coping with Scoping":

http://perl.plover.com/FAQs/Namespaces.html


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas


All times are GMT. The time now is 04:35 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.