Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Perl
Perl Misc
Pattern matching : not matching problem
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Marc Bissonnette, post: 4752127"] Hi all; The answer to this is probably simple, but I can't figure it out :( I want to test a string for a value in a content-checking subroutine: If there is a match (if it meets criteria), then it is to continue on with the rest of the sub. If it fails the match, then I want to display an error. I (obviously) have not understood the 'not match' rules or usage: #!/usr/bin/perl use strict; use warnings; my $string = "foobar"; my $matchstring = 'foo'; if ($string ne~ /$matchstring/) { print " No Match\n"; } else { print " Match\n"; } Results in " Match" no matter what is in $matchstring or $string. The interpreter also replies with "Use of uninitialized value in pattern match (m//) at c:\test.pl line 7" Which I thought was supposed to be the purpose behind declaring the vars with my up front... I've tried if ($string ne /$matchstring/) and if ($string !=~ /$matchstring/) even though != is supposed to be numerics. I know I can test for a positive match (ie. if $string =~ /$matchstring/) { #do something; } else { #do something else; } But I'm curious as to why I can't do the "If this doesn't match do this" type of approach. I would be most appreciative for any insight you could provide. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Perl
Perl Misc
Pattern matching : not matching problem
Top