Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Help needed understanding global variables in Perl

by rinceWind (Monsignor)
on Mar 05, 2002 at 09:19 UTC ( #149309=note: print w/replies, xml ) Need Help??

in reply to Help needed understanding global variables in Perl

Dear Anonymous Monk,

you have a number of questions rolled into your query. My first piece of advice is to read perlsub in the core documentation, if you have not already done so.

Why do you need global variables? You rarely need them in C. If you are wanting to preserve state information between subroutine calls, you should look at using a class, see perltoot object tutorial, or a closure, see Funkyness with closures....

Also, if the declaration of the sub is inside a block, it has access to 'my' variables declared in the block before the sub, which will keep their value between calls.

Hope this helps and I haven't confused you too much


  • Comment on Re: Help needed understanding global variables in Perl

Replies are listed 'Best First'.
Re: Re: Help needed understanding global variables in Perl
by rbrito (Acolyte) on Mar 06, 2002 at 02:48 UTC

    Oh, sure, I understand that global variables are bad in practice (read: "the real world"). But my question was more theoretic, in the sense that I'm just trying to have a solid background on the language and understand its semantics from the viewpoint of a user.

    Unfortunately, I still have not understood completely the use of (user-defined) global variables with Perl.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://149309]
[atcroft]: .oO(Then there is the effect if a site changes their timezone, such as when the International Date Line was moved by the purchase of Alaska by the US from Russia in 1867, or several places (I cannot recall off-hand) that moved from one side of the Date
[atcroft]: Line to the other recently....)
[atcroft]: .oO(Then again, you also have to be careful if you had it to the database, and be aware of any assumptions it makes (such as SQLite assuming Gregorian calendar and a day of exactly 86400 seconds)...)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-04-29 04:49 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (531 votes). Check out past polls.