SPUG: question regarding using reg exp in "if" statements.
Kevin Fink
kevin at n2h2.com
Fri Sep 10 16:44:17 CDT 1999
What you're looking for is:
if($string =~ /^\s*$/) { } else { }
^ Anchor to beginning of string.
\s* Match zero or more instances of any string of whitespace
characters.
$ Anchor at end of string.
Kevin
On Fri, 10 Sep 1999, Daniel V. Ebert wrote:
> I have written an "if" statement:
>
> if ($string eq "") { whatever;}
> else{ something else;}
>
> to check for blank entries in a form CGI. This works except that " "
> doesn't satisfy the if statemenet condition.
>
> What I really want is (in plain English) is:
> if ($string is only white space)
>
> I've tried stuff like:
>
> if($string eq /\s/)
> if($string ne /\w/)
> if($string eq m/\s/)
> if($string ne m/\w/)
> etc.
> but they don't work. I'm probably missing something obvious, but I can't
> figure it out. Any help would be appreciated. Thanks.
>
> ---
> Dan Ebert <debert at seanet.com> or <mathin at mathin.com>
> Seanet Internet Services
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
> SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
> Email to majordomo at pm.org: ACTION spug-list your_address
>
>
------------------------------------------------------------------------------
Kevin Fink <kevin at n2h2.com> N2H2, Creators of Bess and Searchopolis
Chief Technology Officer 900 Fourth Avenue, Suite 3400
http://www.n2h2.com/ Seattle, WA 98164
VOICE: 206-336-1501 / 800-971-2622 FAX: 206-336-1541
------------------------------------------------------------------------------
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list
mailing list