QUOTE(Sun751 @ 20 Jun, 2009 - 08:37 PM)

CODE
if (defined($ENV{FRUNEXT}) eq 'ifx')
{
print"[ENV is: Informix ]";
$informix=1;
}
elsif(defined($ENV{FRUNEXT}) eq 'msv')
{
$sql=1;
}
elsif(defined($ENV{FRUNEXT}) eq 'ora')
{
$oracle=1;
}
In above code, I am trying to check if $ENV{FRUNEXT} variable is defined or not in every if statement before checking if its 'ifx' 'msv' or 'ora'.
But its seems to be not working, Could any one suggest me where I go wrong? any better way of doing it?
"defined" returns a boolean value, true (1) if the variable is defined and false (an empty string) if it is undefined, so this will never be equal to any of the values you're comparing it against. There's also no need to test definedness every time; if $ENV{FRUNEXT} is defined the first time, it will be defined for the others and vice-versa, unless you do something to change it.
I would rewrite the section of code you posted as:
CODE
if (defined $ENV{FRUNEXT}) {
if ($ENV{FRUNEXT} eq 'ifx')
{
print"[ENV is: Informix ]";
$informix=1;
}
elsif($ENV{FRUNEXT} eq 'msv')
{
$sql=1;
}
elsif($ENV{FRUNEXT} eq 'ora')
{
$oracle= 1;
}
}
If you're using perl 5.10 or later, this would also be a good place to use given/when, but I'm assuming that you (like most of the world) are still using 5.8.x.