in reply to variable initilization

I feel for you.
You are tasked with modifying very bad code.

Things go wrong from the very first program statement.
cwd is a "buzz word" meaning: current working directory.

Without getting into fancy stuff, I show below why the first statement is wrong ('cwd' is almost certainly not what is intended for $Kitdir). And then I say that there is no need to translate "forward slash" to "back slash". Perl will do that for you when it is necessary as a path name! I show you that this translation works, but don't do it!

$KitDir = cwd; print "$KitDir\n"; # prints 'cwd' use Cwd; $Kdir = getcwd(); # $Kdir is: Where am I? print "$Kdir\n"; # prints 'C:/TEMP' $Kdir =~ s|/|\\|g; # not necessary! Don't! print "$Kdir\n"; # prints 'C:\TEMP'
So that covers your first 2 program statements.
$ENV{'KITDIR'} = $KitDir; #assigns $KitDir value to #KITDIR key in ENV hash
In the below:
I don't think that $ENV{'KITDIR'} will wind up with what you think it will.
$KitDir = $ENV{'KITDIR'}; if ($KitDir eq "") { $KitDir = $Config::Conn{KitDir}; }
I suppose we could have:
$ENV{'KITDIR'} ||= $Config::Conn($KitDir);
but it is hard for me to see how $ENV{'KITDIR'} could be false given the above statements.

Replies are listed 'Best First'.
Re^2: variable initilization
by mtrasp (Acolyte) on Nov 25, 2009 at 21:24 UTC
    Thank you very much for your reply still iam not understanding this perl expression $Kdir =~ s|/|\\|g;    # not necessary! Don't! can you please reply Thank you
      This is a substitution expression that changes forward slash to a backward slashes. The windows command line needs to have backward slashes while Unix uses forward slashes. With Perl you can use forward slash on both types of systems provided that this is in a Perl function call not a shell cmd to the native OS. I always use forward slash in Perl code. The backward slash has a purpose as an escape character, hence the need for this backslash backslash to mean one backslash. That is not an issue for the forward slash and resulting regular expressions are easier to understand.