On 2/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Thank you both. I am trying to find out why "!~" operator fails. It is due to the whitespaces. but I am using "six" to ignore spaces. Sorry guys. Below is the actual code. I made the changes that A.R. Ferreira suggested and it fails. use strict; use warnings; my $rdns="cn=Exchange Sites,cn=Proxy Views,cn=JoinEngine Configuration,ou=Conf,o u=InJoin,ou=applications,dc=marriott,dc=com"; my $result="cn=Exchange Sites"; if ($result !~ /\Q$rdns\E/six) { print "\nresult: '$result'"; print "\nrdn: '$rdns'\n"; } else { print "String is there\n"; } OUTPUT is: $ ./test.pl result: 'cn=Exchange Sites' rdn: 'cn=Exchange Sites,cn=Proxy Views,cn=JoinEngine Configuration,ou=Conf,ou=InJoin,ou=applications,dc=marriott,dc=com' Tom your code works fine. But I was tring to understand why "!~" fails above.
It fails because *all* of $rdns is not in $result1. The regex on the right is matched against the operand on the left. So, $result1 =~ /$rdns/ means "see if $result1 contains the pattern $rdns". What you wanted to say was "see if $rdns contains the pattern $result1." Or, if you want to think about it the other way 'round: "see if pattern $result1 appears in $rdns." That is written as $rdns =~ $result1 To negate it ("make sure $result1 doesn't appear in $rdns"), you can use !~ instead. If you aren't using regex metacharacters (*,.,?, etc.), it is probably both simpler and faster to use index: index($rdns, $result1) That says "see if the substring $result1 appears in the string $rdns." HTH, -- jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!