in reply to Inconsistent for the sake of convenience

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?

Replies are listed 'Best First'.
Re^2: Inconsistent for the sake of convenience
by Porculus (Hermit) on Feb 17, 2009 at 21:06 UTC
    Your split example is, of course, inconsistent in a way you didn't mention: but for the magic of split (or lack of magic, as perlre puts it), that // would probably mean /o?/.