The regular expression behavior is not specific to Perl. Everyone does it that way, and it is done so that $ in regular expressions will behave the way it does in the grep utility.

If you want a better convenient inconsistent regular expression behavior, ask yourself why the following are not endless loops:

@matches = ("foo" =~ /o?/g); my @chars = split //, "foo";
In both cases shouldn't the pattern match before f, then before f, then before f...? See perlre for an explanation. You probably understood the explanation there if you see why pos($string) = pos($string) is not a no-op.

An inconsistency that I like is the (now useless) feature that the line "nose hairs"; generates a warning but "ignore my nose hairs, please"; does not. See How to make warnings disappear for further discussion and an explanation. It also explains why the feature has been useless since before I learned Perl.

If you want a lot more inconsistency for the sake of convenience though, consider how context works in Perl and look how core parts of the language such as localtime, grep, and @array behave depending on context.

And one general thought for this thread. As you review these examples, ask yourself whether it is a coincidence that Larry Wall was a repeat winner of the International Obfuscated C Contest? Or that his 1986 win was in the category Useful Obfuscation?


In reply to Re: Inconsistent for the sake of convenience by tilly
in thread Inconsistent for the sake of convenience by ELISHEVA

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.