...because greediness does not affect its result in any way.

I was hoping someone would have an idea as to what he might have been thinking.

You're only thinking about the final outcome. Sometimes, changes are not made for the outcome, but because it changes how it performs, and one method may be better for the normally expected input.

Unfortunately, in this case, I'm not seeing that on my system the non-greedy being significantly better at matching the short version, and it's significantly worse at matching the long version:

use Benchmark qw(cmpthese); my $f = '-f'; my $f2 = '-field'; cmpthese( 500000, { 'ng_short' => sub { $f =~ /^-f(i(e(ld??)??)??)??$/ }, 'ng_long' => sub { $f2 =~ /^-f(i(e(ld??)??)??)??$/ }, 'g_short' => sub { $f =~ /^-f(i(e(ld?)?)?)?$/ }, 'g_long' => sub { $f2 =~ /^-f(i(e(ld?)?)?)?$/ }, } ); # Rate ng_long g_long g_short ng_short # ng_long 88339/s -- -54% -73% -74% # g_long 193798/s 119% -- -41% -42% # g_short 328947/s 272% 70% -- -2% # ng_short 335570/s 280% 73% 2% --

Oh -- and it _does_ change the values of $1, $2, $3, but we have no reason from the code snippet given that they're important.,/strike>

Update: Removed extra comma, resulting in sloppy english grammer, and stressed the 'not'. Was :

Unfortunately, in this case, I'm not seeing that on my system, the non-greedy being significantly better at matching the short version ...

Update: tye is correct in the lack of difference. Why a non-greedy expression would match 1 when it has the option of matching 0 makes no sense to me, though.


In reply to Re^3: Dominus on the non-greedy version of the ? quantifier by jhourcle
in thread Dominus on the non-greedy version of the ? quantifier by Aristotle

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.