in reply to Handling undefined string content
Use a regex to see if the string contains only spaces (or whitespace, which also includes [ \t\r\f\n]):
print "Spaces only\n" if $var =~ /^ +\z/; print "Only whitespace\n" if $var =~ /^\s+$/; print "Whitespace or empty\n" if $var =~ /^\s*$/;
I used \z as the end of string anchor on the first one because you didn't specify whether the string was a line and a \n at the end might not be acceptable.
|
|---|