Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Environment variable

by lostjimmy (Chaplain)
on Mar 12, 2010 at 13:54 UTC ( [id://828295]=note: print w/replies, xml ) Need Help??


in reply to Environment variable

What, exactly, is your question? If you want to compare more env variables, just add more comparisons.

To make it easy, you can put your environment variables and their expected values in a hash, then make the comparisons in some kind of a loop.

Replies are listed 'Best First'.
Re^2: Environment variable
by rohit2007 (Novice) on Mar 12, 2010 at 14:14 UTC
    I want to write a programme in perl which can compare values of different ENVIRONMENT VARIABLES(env var) with the default variables and it should give a warning when the value of environment variable is not same as my default value. I have a small peice of programme which can compare the value of an environment variable. lets say i have in total 20 env var, but i m intrested in 10 env var(a1, a2, a3,.....,a10) their default values are (b1, b2, b3,......, b10). Now in Perl we have environment variables defined in $ENV so i want to take these 10 ENV VAR (a1,....,a10)compare their values from default and then tell if they match or not. for sure i can write this same thing ten times and get the work done but i m looking for an easier alternative(as done in the previous post). Thank you for your help!!
      I believe the simplest method would be to put the defaults in an array and the ENV-vars as well, then you could use grep or array::compare or something like that to find out differences, like
      my @defaults = (b1,..,b10);
      my @envs = (a1,..,a10);
      print "errors" if grep { $envs[$_] !~ $defaults[$_] } 0..9; this is untested and maybe not the most elegant, but I must confess I have not entirely understood your problem...
      Hope it helps...

        The hash methods are simpler, since they link the two lists implicitly.
        Loop over the keys, and if the value doesn't match the environment variable, then it is wrong.

        And no chance of your keys and values getting out of synch when you want to add one!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-20 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found