Without any modifiers $ matches the end of the string. But for practical reasons it sort of ignores a newline there. The practical reason is that you often read in lines from files and want to match without first having to chomp the line. A convenience for very small scripts and one liners. Here is a relevant citation from the perlre man page:
By default, the "^" character is guaranteed to match only the beginning of the string, the "$" character only
the end (or before the newline at the end), and Perl does certain optimizations with the assumption that the
string contains only one line. Embedded newlines will not be matched by "^" or "$". You may, however, wish to
treat a string as a multi-line buffer, such that the "^" will match after any newline within the string (except
if the newline is the last character in the string), and "$" will match before any newline. At the cost of a
little more overhead, you can do this by using the /m modifier on the pattern match operator. (Older programs
did this by setting $*, but this practice has been removed in perl 5.9.)
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||