M
Marc Bissonnette
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.
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.