HOWTO:Dynamically getting all of the global variables and their v alues

2003-07-01 Thread Ken Lehman
I would like to write a function that will get all the global variables that
are declared in my script plus their values( which will all be strings if
that matters). This is what I have so far:

my ( $varName, $globValue );

while ( ($varName, $globValue) = each %main:: )
{
  print \$$varName $globValue \n;
}


This prints a whole lot of stuff including function names but the variables
are not in here. My goal is to have this function pick up the variables
dynamically everytime the script is run, get the values and do some
varification before getting into the meat of the script, without having to
add or remove the variables manually from the sub whenever I add or remove a
variable from the script. 
Thanks in advance for any help
-Ken



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: HOWTO:Dynamically getting all of the global variables and their v alues

2003-07-01 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Ken Lehman wrote:
 I would like to write a function that will get all the global
 variables that are declared in my script plus their values( which
 will all be strings if that matters). This is what I have so far:
 

Why use global variables when you could use a hash which gives you a key plus 
whatever type of data needed.  I do this all the time. Allows me to put everyhting in 
one spot and I use this vairable hash for holding all the necessary data that I need 
to have.

A thought.

Wags ;) 


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: HOWTO:Dynamically getting all of the global variables and their v alues

2003-07-01 Thread Charles K. Clarkson
Ken Lehman [EMAIL PROTECTED] wrote:
: 
: I would like to write a function that will get
: all the global variables that are declared in
: my script plus their values( which will all 
: be strings if that matters). This is what I
: have so far:
: 
: my ( $varName, $globValue );
: 
: while ( ($varName, $globValue) = each %main:: )
: {
:   print \$$varName $globValue \n;
: }
: 
: 
: This prints a whole lot of stuff including
: function names but the variables are not in
: here.

Then the variable you are referring to
are probably lexical (declared with 'my').
Lexical variables do not show up in the
symbol table (%main::).

: My goal is to have this function pick
: up the variables dynamically every time
: the script is run, get the values and
: do some verification before getting
: into the meat of the script, without
: having to add or remove the variables
: manually from the sub whenever I add
: or remove a variable from the script. 
: Thanks in advance for any help

Another poster mentioned the idea
of creating a module full of constants.
This allowed him to use any data type
and to use subroutines for very complex
data. All the constants could be
exported when the module is used.

This still imports everything to the
main namespace and since constants are
traditional ALLCAPS, provides the next
programmer to easily recognize that they
may indeed be constants imported into
the script.


HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]