in reply to What is the best way to determine if a string is blank?

Well, personally, I'd use the defined() method, which returns false if it's passed a blank string, true otherwise:
if ( ! defined($foo) ) { #do something kool } else { #do something not so kool }
______________________________________________
It's hard to believe that everyone here is the result of the smartest sperm.

Replies are listed 'Best First'.
Re: Re: What is the best way to determine if a string is blank?
by repson (Chaplain) on Jan 04, 2001 at 06:02 UTC
    That wouldn't do what is intended. Look at these cases...
    my $var1; my $var2 = undef; my $var3 = ""; my $var4 = 0; my $var5 = 1; my $var6 = "foo"; for ($var1,$var2,$var3,$var4,$var5,$var6) { print defined($_)?1:0 . "\t" . ($_)?1:0 . "\n"; } __END__ Output: 0 0 0 0 1 0 1 0 1 1 1 1
      yeah, i guess you're right, because it returned true with $var3...but as for $var4 and $var5, the ($_)?1:0 is checking if they're TRUE or FALSE, not whether they're defined. still, i get your point.

      ______________________________________________
      If the world didn't suck, we'd all fly off.
             -A friend of mine