Forum Moderators: coopster & phranque

Message Too Old, No Replies

perl logic, and a "gotcha"

where does one find good info on perl logic?

         

jeremy goodrich

8:37 pm on Apr 10, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have at my disposal some of the books, perl cookbook, learning perl, and programming perl, all by O'Reilly. Excellent works, all of them.

One of the things I tried to write didn't work all day today, and somebody finally pointed out the error.

The following code, much to my chagrin, I found doesn't work:

if ($l[1] != /^http/)

Finally, somebody told me this:

if(!($l[1] =~ /^http/) )

Apparently it has to do with the logic of pattern matching, and you can't "not match" something. you have to match it, and then say not that...or something.

Is there anywhere where I can read about this specifically? I'm getting tired of wise a** programmers at work poking fun...

sugarkane

10:10 pm on Apr 10, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem with your original code is that != means 'does not equal' rather than 'does not match' - the correct operator for 'does not match' is !~

So, your original code would be

if ($l[1] !~ /^http/)

Hope this helps,