if ( /^[brc]at$/ ) { # match "bat", "rat", or "cat"
print "It's an animal\n";
if ( /^b/ ) {
print "... and it flies!\n";
}
}
This is not the same as:
if ( /^[brc]at$/ ) {
print "It's an animal\n";
}
if ( /^b/ ) {
print "... and it flies!\n";
}
Because the latter will match any word that starts with b.
Of course, in this case, it seems obvious that if the numbers are equal, they will also be within +/- 1 of each other, but mistakes like the above can happen if you don't think the logic through (and test it!).
Update: For example, consider the special case of Inf that syphilis suggested, which I've now added as a test case to my other post.
|