There's a typo in:
if($_ =- m/$pat/g)
The =- should be =~.
Ps: From now on, wrap your code in <code> tags. See Writeup Formatting Tips, | [reply] [d/l] [select] |
Others have identified the error. diagnostics can give you a more verbose explanation of warnings:
(W syntax) You wrote your assignment operator backwards. The = mu
+st
always comes last, to avoid ambiguity with subsequent unary operat
+ors.
In this case, it does not tell you how to correct your problem, but perhaps it makes you look at your issue from a different angle.
| [reply] [d/l] |
On line 11 you have =-, which is what the error/warning is referring to. From the context, I think you meant to use =~.
| [reply] [d/l] [select] |
In a previous thread we asked if you would please wrap your code in <code></code> tags. ...several times. You've also been /msg'ed on the subject. Now it's time for the public shaming. ;)
If there's no degree of shame sufficient to motivate you to heed previous advice by using <code></code> tags around your code, and <p></p> tags around your paragraphs, perhaps you could do it in the future as a way of saying thank-you for the free Perl related advice you have gotten here. Writeup Formatting Tips.
Why, you might ask. You're already getting answers to your questions, after all. Apparently posting without code tags is getting you the desired result. Well, the answer is because it makes it easier for people to read your posts, and requires less work from the Janitors, who may need to edit your posts after the fact to make them legible. We also spend less time trying to decipher clearly formatted posts, and as a result, we tend to provide more thorough and on-target answers. And, frankly, because we prefer it to be done that way. We want you to be a part of the Monastery, and we would rather that as a fellow Perlmonk you take a few minutes to familiarize yourself with how make your posts more legible.
| [reply] [d/l] [select] |
In your example:
#!/perl/ -w
$pat=''; #thing to search for #line 3
while(){
print 'Enter the pattern';
chomp($pat =<stdin>);
print 'enter the string:';
chomp($_ = <stdin>); #10
if($_ =- m/$pat/g) {
print "true\n";
}
else{print "false\n";}
}
There is only one "pattern match operator" and that is: m/$pat/g. And the only problem with that is the use of the /g option, which in this case is superfluous.
Your problem is that the characters between $_ and m/$pat/g are not a valid perl operator.
| [reply] [d/l] [select] |