Test for an empty string

Sometimes I need to see if there is anything in a string, so I looked for a random tutorial from someone I didn’t know to give me the answer, like http://w3mentor.com/learn/perl/perl-string-manipulation/test-empty-strings-in-perl/.

The defined operator is too much to type, so I can use some of the other options I found on that random page:

if($mystring) {
#variable is undefined
}
if($mystring eq undef) {
#variable is undefined
}

Dave Cross says those don’t work and everyone should just use defined.

Post to Twitter Post to Delicious Post to Digg Post to Facebook

Leave a comment

1 Comments.

  1. I actually wrote a lot more in that comment, but they edited it so that the most critical stuff was removed.

Leave a Reply

You must be logged in to post a comment.