Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Find ,if already a environment variable is set in hash table

Status
Not open for further replies.

kraj123

Programmer
Joined
Aug 23, 2007
Messages
7
Location
US

Hi,

How to Find ,if already a environment variable is set in hash table in perl.

Actually i want to check if a environmental variable in perl script, which is present in oracle database has been already set its path in hash table in perl.

that is i have to query the database server and check whether it has been set as environment variable or not.

so basically i want to check with if statment to sdatabase erver name and a loop to check for all variables present in perl by quering the database....to find those variables has been set as environment variable or not.....if present it should be in hash table....

so i need the syntax and proper logic to test this......

it would be great if anyone can help me out...

--------------------------------------------------------------------------------
 
what code have you already written?



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Hi,

I am new to perl. Thanks for the response.

Actually I have a windows batch script. I want to write the same script as perl script. I am pasting the batch script below....in that first i have to set environment variable in perl as in the batch script. so for that i have check if those variables is already set in perl hash table...so i was advise to query the database server to check for that....but i am not clear...

in the below batch script like set arpp=itsm70-ru...these are all environment variables in batch script which i have to set in perl..

I would be great, if u can help me out....thanks a lot...

batch script...is here...


:: ITSM 7.0. It was called wailea, but the final Russian stage had become 'x-volga'
:: and it was older so it's ccm\gandalf\system\... instead of the new ccm\gandalf\%arapp%\system\...
:: Also, itsm70 used ard instead of i18n. Only care about Russian at this point.

setlocal enableextensions enabledelayedexpansion

set arapp=itsm70-ru
set components=
set integrations=
set pathlets=
set locales=ru
set byp=c:\output\%arapp%\byproducts

:: use a component if there seems to be a trdb for the views in it
pushd Z:\l10n_test\system
for /D %%c in (*) do (if exist .\%%c\ar\common\ard\*forms.csv set components=!components! %%c)
popd
pushd Z:\l10n_test\integration
for /D %%c in (*) do (if exist .\%%c\ar\common\ard\*forms.csv set integrations=!integrations! %%c)
popd

: generate 'pathlets' which usually come in handy.
for %%c in (%components%) do (set pathlets=!pathlets! system\%%c)
for %%c in (%integrations%) do (set pathlets=!pathlets! integration\%%c)

mkdir %byp% 2>nul

:: pass in the desired output file, the English arlabel folder, the English defs folder
:: 14Jun07 change this for Greg to...
:: pass in the desired output file, the combined forms trdb , the English defs folder
:: (need echo. to echo a return. People sometimes forget the final return)

:: make TRDB
del /Q %byp%\*.combined.trdb.csv
for %%c in (%pathlets%) do (^
for %%f in (Z:\l10n_test\%%c\ar\common\ard\*end_forms.csv) do (type %%f >> %byp%\%%~nxc.combined.trdb.csv && echo.>> %byp%\%%~nxc.combined.trdb.csv))

:: make PATTERNS
for %%c in (%pathlets%) do (^
call "generate driver patterns.pl.bat" %byp%\%%~nxc.vui.pattern.export %byp%\%%~nxc.combined.trdb.csv Z:\l10n_test\%%c\ar\en\def)

:: make SCRIPTS from the patterns
call c:\localization\viewservers\%arapp%.bat
for %%v in (%locales%) do (^
for %%c in (%pathlets%) do (call "make scripts from pattern.bat" %byp%\%%~nxc.vui.pattern.export %%v %byp%\%%~nxc.vui.%%v.export))

:: take SNAPSHOTS
for %%c in (%pathlets%) do (^
for %%v in (%locales%) do (call "core extract.bat" %byp%\%%~nxc.vui.%%v.export %%v C:\output\%arapp%\%%c\ar\%%v\def))

:: use ARAXIS
for %%c in (system) do ("C:\Program Files\Araxis\Araxis Merge 2000 Professional\merge.exe" Z:\l10n_test\%%c c:\output\%arapp%\%%c /NoSplash /NoSplashDelay)
 
$ENV{'arapp'}='itsm70-ru';

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi Kevin,

thanks...yes i tried it. But now the problem is how do i know that the value for for instance how to find arpp ='something' is already set in hash table or not....

just if we try print $ENV{'arapp'}, if some value comes up..then it is already set...

also i want to know this option like...putting all variables as name vale pair in config file , then reading it in perl to hash map...how should i do it...so that it can be shared for all other scripts...

thanks a lot for helping me..
 
just if we try print $ENV{'arapp'}, if some value comes up..then it is already set..."

that might work OK for your needs.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
You mean like this ?
Code:
if(exists($ENV{"PATH"})) {
	print "PATH EXISTS\n";
}
 
Kevin,

I really appreciate for your response...
Yes kevin exactly...but with your same if condition, I want to first connect to a server by giving server name, then using query , I want to find for multiple environment variables, that the value has been set already in hash map in perl.
 
Hi Kavin,

Now, I am what I am trying is....

I am putting all environment variables in config file. Then with the below code trying to read that in perl file and put entry in perl hash table , so that those env variables can be accessed by any script.

if (open(APPCF, "$APPHOME/config/itsm.cf")) {

while (<APPCF>) {
my($name, $value) = /^\s*([A-Za-z_][^= ]*)=(.*)\n/;
next unless ($name);
$APPCF{$name} = $value;
}
close(APPCF);
}

I am putting this code in perl script. But what path I have to put for itsm.cf file.

and without this can I use require ".setting" for the same purpose...

so before this I have connect server query and check if those env variables have already been set. I am trying hard with syntax...

It would be great ..if you can help me out...

thanks and regards
raj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top