Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl Monk, Perl Meditation

Re^3: Strange Regex Behavior

by quester (Vicar)
on Dec 06, 2011 at 07:12 UTC ( #941967=note: print w/ replies, xml ) Need Help??

in reply to Re^2: Strange Regex Behavior
in thread Strange Regex Behavior


Comment on Re^3: Strange Regex Behavior
Re^4: Strange Regex Behavior
by BrowserUk (Pope) on Dec 06, 2011 at 07:25 UTC

    Hm. I believe the fact that the entire ternary expression is wrapped in parens means that the contents of those parens must be evaluated before anything outside them per perlop:


    I also believe that as the two ternary expressions are part of a (4-term) comma separated list, those four terms should be evaluated in strictly left to right order per perlop:


    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Ah... yes. That would make it a bug. Sorry.

      It doesn't seem to be the ternary operator causing the havoc, or pattern matching though:

      $,=", "; my $i; print $i++, $i, $i++, $i, $i++, $i;


      0, 3, 1, 3, 2, 3

      Using Dump, we can see that the optimizer is assuming that $1 must be constant for the length of time it takes to evaluate the list:

      use Data::Dump::Streamer; my $i; print Dump \($i++, $i, $i++, $i, $i++, $i);


      $SCALAR1 = \do { my $v = 0 }; $SCALAR2 = \do { my $v = 3 }; $SCALAR3 = \do { my $v = 1 }; $SCALAR4 = $SCALAR2; $SCALAR5 = \do { my $v = 2 }; $SCALAR6 = $SCALAR2;

      The autoincrement is also not a necessary ingredient:

      use Data::Dump::Streamer; print Dump \("x"=~/(x)/, $1, "y"=~/(y)/, $1, "z"=~/(z)/, $1);


      $SCALAR1 = \do { my $v = 'x' }; $SCALAR2 = \do { my $v = 'z' }; $SCALAR3 = \do { my $v = 'y' }; $SCALAR4 = $SCALAR2; $SCALAR5 = \do { my $v = 'z' }; $SCALAR6 = $SCALAR2;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://941967]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-03-16 12:26 GMT
Find Nodes?
    Voting Booth?

    Have you used a cryptocurrency?

    Results (326 votes), past polls