Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

2 questions about anonymous storage and global variables

by cosmicperl (Chaplain)
on Jan 13, 2006 at 00:48 UTC ( #522851=perlquestion: print w/ replies, xml ) Need Help??
cosmicperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
  I've got a situation and I'm trying to find the right code for it that strict pragma will agree with.
Firstly I have a scalar that will contain either a value or a reference to an array. If it's an array I want it to do one thing. If it's a scalar value I want it to do another. What's the correct way of doing this so I don't get errors?
Secondly How can a make a global variable truely global, so that it will be accessible by all packages without using package::variable.

Thanks again
Lyle

Comment on 2 questions about anonymous storage and global variables
Re: 2 questions about anonymous storage and global variables
by Enlil (Parson) on Jan 13, 2006 at 01:04 UTC
    Firstly I have a scalar that will contain either a value or a reference to an array. If it's an array I want it to do one thing. If it's a scalar value I want it to do another. What's the correct way of doing this so I don't get errors?

    Have a look at ref in the documentation. It has a couple of examples of what you are looking for.

    Secondly How can a make a global variable truely global, so that it will be accessible by all packages without using package::variable.

    You don't. Well sortof, Can you create *real* global variables?

    hth
    -enlil

      Thanks that has cleared that up for me. I've read about ref in the past but couldn't for the life of me remember or find on the net. Maybe is should practice some new searching techniques.

        For a basic function like that, perlfunc is often a good place to start when the exact function has slipped your mind.

        -xdg

        Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2014-08-29 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls