Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: changing package variables?

by jasonk (Parson)
on Mar 04, 2003 at 23:50 UTC ( #240488=note: print w/replies, xml ) Need Help??


in reply to changing package variables?

Because the variable in the package is declared within the scope of that package. So basically you now have two variables:

$MYPACKAGE::var1 contains 'DEFAULT I WANT TO CHANGE'
$main::var1 contains 'PRINT THIS'.

You need to peruse perlvar and the docs for the package command.

Replies are listed 'Best First'.
Re: Re: changing package variables?
by LameNerd (Hermit) on Mar 05, 2003 at 00:06 UTC
    Thanks!
    I was under the mistaken impression that doing
      use MYPACKAGE qw / sub1 /;
      use vars qw / $var1 /;
    
    Would give me instance of $MYPACKAGE::var1 in my main package scope.
    So what's the diffence between
      use vars qw / $var1 /;
    
    and
      my $var1
    
    ?????? What was I thinking?

      In a nutshell :my does not declare a package variable. use vars does. There's a wealth of information on this topic in the Tutorials section of the site (subsection "variables"); I'll plug my Variable Scoping in Perl: the basics and Dominus' Coping With Scoping specifically.

      update adjusted the link to CwS to point directly to it.

      If not P, what? Q maybe?
      "Sidney Morgenbesser"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://240488]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2023-12-09 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (38 votes). Check out past polls.

    Notices?