Q:

Perl If statement without parameters just plain variable is the EXP

I just wanted to know what does this code do?
my $string_1 = "foo bar";
my $val = 3;

if($string_1) {  

}

basically what happen if you just use a variable inside an if statement?
thanks

A:

It checks if the value of the variable is true. In Perl, everything is true but the following:

0 and the string '0'
undef
() (the empty list)
'' (an empty string)

This is documented in perlsyn. It also works with any other kind of value. You can also put a string, a function call inside the if condition. The behavior is always the same.

