List Info

Thread: Code help




Code help
country flaguser name
United States
2007-03-21 06:09:51

I'm trying to do a conditional if statement but the results I'm
getting back are not the desired ones.

$novar = `env | grep VAR`;

if (($novar eq "VAR=1") || ($novar =~ m/s/)) {
something
}else
{
something
}


If I run the command "env | grep VAR" at the command line this VAR
is not set it will come back with nothing. For example -

$ env | grep VAR
$

I thought that was considered whitespace so I did an OR with $novar
=~ m/s/ but it's not catching it and dropping to my esle line.
Could someone help me out and let me know what I'm doing wrong?

Thanks

__._,_.___
.

__,_._,___
Re: Code help
country flaguser name
United States
2007-03-21 06:14:35

doing chomp should solve your problem

$novar = `env | grep VAR`;

chomp $novar;

if ( $novar eq "VAR=1" or $novar =~ /s*/ ) {

#something

}
else {

#something

}

HTH

On 3/21/07, perl_1978 < perl_1978%40yahoo.com">perl_1978yahoo.com> wrote:
&gt;
> I'm trying to do a conditional if statement but the results I'm
> getting back are not the desired ones.
&gt;
> $novar = `env | grep VAR`;
&gt;
> if (($novar eq "VAR=1") || ($novar =~ m/s/)) {
> something
> }else
&gt; {
> something
> }
>
>
>; If I run the command "env | grep VAR" at the command line this VAR
> is not set it will come back with nothing. For example -
>
> $ env | grep VAR
> $
>
> I thought that was considered whitespace so I did an OR with $novar
&gt; =~ m/s/ but it's not catching it and dropping to my esle line.
&gt; Could someone help me out and let me know what I'm doing wrong?
&gt;
> Thanks
&gt;
>
>

--
~ Kishore Balla

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )