Newbie: Please me define global parameters

Discussion in 'Perl Misc' started by mmasroorali@cse.buet.ac.bd, May 5, 2005.

  1. Guest

    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.
     
    , May 5, 2005
    #1
    1. Advertising

  2. <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, May 5, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    646
    Big Brian
    Oct 14, 2003
  2. theotyflos
    Replies:
    3
    Views:
    482
    Thomas Matthews
    Feb 19, 2004
  3. robin liu
    Replies:
    3
    Views:
    832
    Robin Liu
    Apr 21, 2006
  4. eiji
    Replies:
    5
    Views:
    481
    Rolf Magnus
    Dec 6, 2005
  5. OK
    Replies:
    5
    Views:
    628
    Peter Bromberg [C# MVP]
    Nov 26, 2007
Loading...

Share This Page