rather than continuing to cargo-cult
code. I have a question refering to your answer (i.e. /\A\d\z/
), that being, when there are no modifiers on the regular expression what is the difference between \A
? (i have read perlre and gone through MRE, but want to make sure I am not missing any subtlies).
While I agree that your answer is better than mine in some respects, the OP did not have a chomp statement, and I assumed perhaps incorrectly that someone would type in a number and thus the newline character would go along with whatever number (or other input) the user typed in and not being chomped out (or removed by any other method), then nothing would ever match with \z (so I am at fault for making so many assumptions and not clarifying more fully). I think at least a couple of the answers (including mine) do mention the fact that $ matches the end of the line or right before the newline character at the end of the line.
But as I mentioned before, I do agree with you, if all you want in a string is to insure that the string is only one digit without anything else in the string (and your using a regex for the checking), then /\A\d\z/ is the correct way to go about it. :)