For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > November 2006 > Please explain usage of m









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Please explain usage of m
AM

2006-11-29, 6:59 pm

Hi all:

Would you please tell me what this means:
$pstrtype = "0" unless ( $pstrtype =~ m#\S# );

My understanding: set $pstrtype to "0" if $pstrtype matches
non-whitespace character

Now, does it mean the match is true if $pstrtype
a.) contains non-whitespace characters in all positions of the string
b.) contains non-whitespace characters in first position of the string
c.) contains atleast one non-whitespace character in some position in
the string

Please help!

Thanks!
Anu M

kens

2006-11-29, 6:59 pm


AM wrote:
> Hi all:
>
> Would you please tell me what this means:
> $pstrtype = "0" unless ( $pstrtype =~ m#\S# );
>
> My understanding: set $pstrtype to "0" if $pstrtype matches
> non-whitespace character


set $pstrtype to "0" UNLESS $pstrtype matches a non-whitespace
character

>
> Now, does it mean the match is true if $pstrtype
> a.) contains non-whitespace characters in all positions of the string
> b.) contains non-whitespace characters in first position of the string
> c.) contains atleast one non-whitespace character in some position in
> the string
>
> Please help!
>
> Thanks!
> Anu M


c. As there are no beginning of string (^) or end of string ($)
anchors, nor any
repitition quantifiers (+ or *). So, it matches any single
non-whitespace character.

It would appear that the value is set to '0' if the string if empty
or only contains
whitespace.

a.) contains non-whitespace characters in all positions of the string

$pstrtype = "0" unless ( $pstrtype =~ m#^\S+$# );

b.) contains non-whitespace characters in first position of the string

$pstrtype = "0" unless ( $pstrtype =~ m#^\S# );

HTH, Ken

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com