rohit2007 has asked for the wisdom of the Perl Monks concerning the following question:
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#!/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" }
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)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 )
Thanking you for your imputs. have a good day!!#!/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!!" }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Environment variable
by toolic (Bishop) on Mar 12, 2010 at 14:38 UTC | |
|
Re: Environment variable
by cdarke (Prior) on Mar 12, 2010 at 14:49 UTC | |
|
Re: Environment variable
by lostjimmy (Chaplain) on Mar 12, 2010 at 13:54 UTC | |
by rohit2007 (Novice) on Mar 12, 2010 at 14:14 UTC | |
by erazor (Initiate) on Mar 12, 2010 at 14:42 UTC | |
by Anonymous Monk on Mar 12, 2010 at 16:05 UTC | |
|
Re: Environment variable
by apl (Monsignor) on Mar 12, 2010 at 14:59 UTC | |
|
Re: Environment variable
by ssandv (Hermit) on Mar 12, 2010 at 17:34 UTC |