I am not an expert on this, but I do think I have an idea of what's going on: AFAIK the state that m//gc keeps is attached to each string (pos). See the output of the following, just your test cases with debugging added:

use warnings; use strict; use Carp; use Devel::Peek; sub parse { Dump $_[0]; ${$_[0]}=~/\Gfoo/gc or confess; } warn "##### Case 1 #####\n"; parse \(''.'foo') for 1..2; warn "##### Case 2 #####\n"; parse \('foo') for 1..2;

In "Case 1", the dot operator (concat) appears* to create a new string on each execution of the loop. In "Case 2", the same string (same memory address etc.) is passed to the function each time, so m/\G.../gc keeps its state, and so the second call fails.

As for B::Deparse, from its docs:

The output of B::Deparse won't be exactly the same as the original source, since perl doesn't keep track of comments or whitespace, and there isn't a one-to-one correspondence between perl's syntactical constructions and their compiled form, but it will often be close.

* Update: Added the "appears to", since my further investigation below has made me uncertain as to what is going on the exact technical explanation is.


In reply to Re: What's going on with either constants folding or B::Deparse output in this case? (updated) by haukex
in thread What's going on with either constants folding or B::Deparse output in this case? by vr

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.