Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Help needed understanding global variables in Perl

by Anonymous Monk
on Mar 05, 2002 at 21:46 UTC ( #149515=note: print w/ replies, xml ) Need Help??


in reply to Re: Help needed understanding global variables in Perl
in thread Help needed understanding global variables in Perl

Yes, one of my questions is indeed that.

But what is the standard way of declaring global variables in Perl? With our? With use vars (which now I know that is obsoleted)? With anything else?

The problem is that even if I don't declare and define anything, I can get rid of warnings just by fully qualifying the variables. In other words, the script below seems to be entirely legal:

#!/usr/bin/perl use strict; use warnings; use diagnostics; $main::f = 42; print "The value is $main::f\n";

The problem is that Programming Perl, 2nd ed. (the one that I have) is not very specific about the subject and I've read already quite a bit of the book (chapters 1, 2, 4, 5 and part of 6).

I don't intent on using global variables, but I feel bad for having trouble not understanding such elementary subjects after reading a fair amount of the documentation.


Comment on Re: Re: Help needed understanding global variables in Perl
Select or Download Code
Re: Re: Re: Help needed understanding global variables in Perl
by arturo (Vicar) on Mar 06, 2002 at 18:14 UTC

    Yes, this is legal code. The answer to your question is that there *is* no mechanism in Perl for declaring global variables. The point of use strict is to force you to think about what you're doing when it comes to variables. It will not, however, prevent you from shooting yourself in the foot. Perl is just not that kind of language.

    On the more general issue: tied up with the whole "global/local" thang is the notion of packages. 'Ave yourself a look at perldoc -f package while you're exploring these issues.

    Finally, lemme recommend, as I have many times before, Dominus' "Coping with Scoping" (follow the link to his page and thence to his site) and, less enthusiastically, my own proposed scoping tutorial.

    I mistrust all systematizers and avoid them. The will to a system shows a lack of integrity -- F. Nietzsche

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2014-09-16 16:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (33 votes), past polls