I want to write a program in perl that should check the environment variables in such a way that they match with some desired variable values(Which is stored in some file text file or xml). These variables could be either a directory,value or path. if the variables are not the same as required..i would like to store it in some log(as in Error,warning or info) and if possible change it to desired value defined in text file. file.
My thought:To start i decided to use hash to store the existing env variables (i tried using array ..but had few referencing problems).firstly instead of reading the desired value from files i hardcoded them in my program(I will change that later). to make it simpler i added to every line weather it is directory,value or path.
Problem:Now i want to read the third element of every line and check if its dir,value or path and then compare it with corresponding actual env variable.if it matches then i would say.this is directory and push it into an array of directory, and also to info log.If it doesn't matches then may be error or waring and corrosponding log.
Please help..any suggestion would help.. Thanks in advance..! Namrata#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %Env = ('PPA_CURRENT_PROJECT' => 'D:\Projects\CurrentProject' => 'D +irectory', 'PPA_DMS' => 'D:\DMS' => 'Directory', 'PPA_DMS_MKL' => 'D:\MKL\ia32\bin' => 'Directory', 'PPA_DataQualityDistributor_CSVFILEPATH' => '\\e4n-00\SR5_ASRRE\CSV' = +> 'Path', 'PPA_DataQualityDistributor_DVLOGSPATH' => '\\e33n-003\SR5_ASRD\DVLOGS +' => 'Path', 'PPA_DataQualityDistributor_INTERMEDIATEFILEPATH' => '\\e34n-001\SR5_A +SRD\INTERMEDIATE' => 'Path', 'USERDNSDOMAIN' => 'PP008.COGY.NET' => 'Value', 'USERDOMAIN' => 'PP008' => 'Value', 'USERNAME' => 'k004lv7w' => 'Value'); #::my @Env_Dir = (\@Env1, \@Env2, \@Env3, \@Env4, \@Env5, \@Env6, \@E +nv7, \@Env8, \@Env9); #::print Dumper \@Env_Dir; my @directory = ();#Array containing environment directory my @path = (); #Array containing environment path my @value = (); #Array containing environment value foreach $_(values %Env) { if ($_ == "Directory") { print 'This is a Directory'; push (@directory, ($Env{$_})); } elsif ($_ == 'Value') { print 'This is a Path'; push (@path, $Env{$_}); } elsif ($_ =='Path') { print 'This is a Value'; push (@value, $Env{$_}); } } print Dumper \@directory; print Dumper \@path; print Dumper \@value;
In reply to Environment Variable by Nams
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |