I am still a beginner with Perl, so please bear with me. This is the situation I’m experiencing:
$var = "AB1234567";
$num = "1234567";
next if $var =~ /$num/;
print "Success!\n";
Now, my understanding is that it should print “Success!\n”, but in reality it doesn’t. However, if I change the regex to next if $var =~ /"$num"/;, this will actually print “Success!\n”.
However, if I change it to $var = "AB123456";, the original regex will work fine.
I understand that when enclosing strings using double quotations, it will dereference interpolate the variable. However, should it not be true in the case of regex? I’ve done regex using variables without quotations and it worked fine.
Thanks for your help!
EDIT:
I left out semi-colons in my example, but my original problem still stands.
EDIT:
I really should’ve just copied/pasted. I made a typo and used continue if instead of next if. Again, my problem still exists.
I think you are confused on what
continuedoes. I’m not really sure of what you are trying to do here, but generallycontinuewill break out of an if-block or go to the next iteration of a for-loop, while-loop, etc. When the pattern does match,continueis actually skipping over the print statement. When you change the value of$var, it no longer matches and the print statement is reached.Try this:
Randy