Hi Friends, I am writing a programme which can check the values of different environment variables and at the same time compare with a standard value if the value does not match with standard value it should give a warning. below you can see a small part of the code which is checking the value of TEMP(environment variable)..I would like to test more than one value at a time.please help me how can i do it. Thanks for your efforts. cheers:)
#!/usr/bin/perl $a = 'TEMP'; $x = $ENV{$a}; if ($x =~ m#\QC:\DOCUME~1\z002n88f\LOCALS~1\Temp\E#) {print "cool\n"; } else { print "$x\n" }
Rohit HI Guys, Thank you all very much for your help!!I really appreciate active participation of all of you guys. With your help and with some surfing I could write this piece of code(please find the code below). This code has some defined environment variables(ENV_VAR) and it checks it with standard $ENV. I wanted to ask is there a possibality to add more values (parameters) to my defined "ENV_VAR"; which gives more detail about the defined ENV_VAR. For eg i say
ClientVersion => 2.24.103; value(attached to clientVersion which tells + that 2.24.103 of ClientVersion is value) COMPUTERNAME => DEB20ZYC; value(attached to COMPUTERNAME which tells t +hat DEB20ZYC is value ) CommonProgramFiles => C:\Program Files\Common Files; path(attached to +CommonProgramFiles which tells that C:\Program Files\Common Files is +path ) APPDATA => C:\Documents and Settings\prr2n88f\Appication Data; path(at +tached to CommonProgramFiles which tells that C:\Documents and Setti +ngs\prr2n88f\Appication Data is path )
In this way is it possible to have two/three values for each of the keys: APPDATA :- 1st value (2.24.103) ; 2ed value (value) CLEARCASE_PRIMARY_GROUP ClientVersion CommonProgramFiles:- 1st value (C:\Program Files\Common Files); 2ed value (path) COMPUTERNAME:- 1st value (DEB20ZYC) ; 2ed value (value)
#!/usr/bin/perl use strict; use warnings; use win32::ole; my (%ENV_VAR) = ( 'ALLUSERSPROFILE' => 'C:\Documents and Settings\All +Users', 'APPDATA' => 'C:\Documents and Settings\prr2n88f\Appication Data', 'CLEARCASE_PRIMARY_GROUP' => 'wp003\05083_ccuser_g', 'ClientVersion' => '2.24.103', 'CommonProgramFiles' => 'C:\Program Files\Common Files', 'COMPUTERNAME' => 'CAL20ZYC'); my $key = keys %ENV_VAR; my $value = values %ENV_VAR; while (($key, $value) =each %ENV_VAR) { print "$key => $value\n"; } if (exists $ENV_VAR{'ClientVersion'}){ print "this Environment variable is present\n";} else { print "This Environment variable is not present\n" } if ($ENV_VAR{ClientVersion} = $ENV{ClientVersion}) { print "$ENV_VAR{ClientVersion}\n" } else { print "Something is going wrong!!" }
Thanking you for your imputs. have a good day!!

In reply to Environment variable by rohit2007

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.