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 and
^? (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. :)
-enlil
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.