Newbie: Please me define global parameters

M

mmasroorali

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.
 
T

Tad McClellan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top