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

Re Bullet 3:
my $foo = " bar"; if($foo =~ /\S/) { print "Whitespace only\n"; }
I think you meant:
my $foo = " bar"; if($foo =~ /^\s+$/) { print "Whitespace only\n"; }
Update: Whoops, davorg is right (see below)... and easier to see. I was thinking \s instead of \S. Fixed above, but hokey, so use his code instead.
--isotope
http://www.skylab.org/~isotope/

Replies are listed 'Best First'.
Re: Re: Re: What is the best way to determine if a string is blank?
by davorg (Chancellor) on Jan 03, 2001 at 23:49 UTC

    Actually it should have been unless ($foo =~ /\S/) to maintain the same logic as the other examples.

    I think you may be confusing \s (whitespace) with \S (non-whitespace).

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me