not or ! ?

H

Huub

Hi,

I'm trying to use 'not' but it gives an error. So, can I do this or is
it too simple thought?

while !(/m\s/g) # While the character being read is no white space
{
...
}

Thank you,

Huub
 
S

Scott Bryce

Huub said:
Hi,

I'm trying to use 'not' but it gives an error. So, can I do this or
is it too simple thought?

while !(/m\s/g) # While the character being read is no white space {
... }

What happened when you tried it?
 
B

Bob Walton

Huub wrote:

....
I'm trying to use 'not' but it gives an error. So, can I do this or is
it too simple thought?

while !(/m\s/g) # While the character being read is no white space

Uh, if you mean what your comment says, you probably want

m/\s/g

as the regex you posted will match an "m" followed by a
whitespace character.

Also, the syntax for the while is incorrect. It is

while(expression){...}

Did you actually try compiling what you posted? It generates a
syntax error.

Even if all that is fixed, the special meaning of //g in a while
doesn't work with a ! in front of the regex (one gets either no
executions of the loop if one or more whitespace characters is
present, or an infinite loop if no whitespace character is
present). Maybe what you want is:

while(/[^\s]/g){...}

?

For example:

D:\junk>perl -e "$_='a b c';while(/[^\s]/g){print 'hi'}"
hihihi
D:\junk>
 
H

Huub

Bob said:
Huub wrote:

...



Uh, if you mean what your comment says, you probably want

m/\s/g

Yes..typo. Should type and read more carefully.
as the regex you posted will match an "m" followed by a whitespace
character.

Also, the syntax for the while is incorrect. It is

while(expression){...}

Yes, (!(m/\s/g)) compiles better.
Did you actually try compiling what you posted? It generates a syntax
error.
Yes.


Even if all that is fixed, the special meaning of //g in a while doesn't
work with a ! in front of the regex (one gets either no executions of
the loop if one or more whitespace characters is present, or an infinite
loop if no whitespace character is present). Maybe what you want is:

while(/[^\s]/g){...}

?

For example:

D:\junk>perl -e "$_='a b c';while(/[^\s]/g){print 'hi'}"
hihihi
D:\junk>
{
...
}
...

Huub
 
S

Scott Bryce

John said:
What happened when you read "but it gives an error"?

I understood that to mean that when he tries 'not' it gives an error. He
didn't tell us what happened when he tried while !(/m\s/g). He
asked us if he can do it. Well, he can try. Did I read that wrong?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top