Can anyone understand why the two lists output by this test program are different? Note the first word of both lists.

Update: Added the references to the outputs to show they hadn't changed.

Update2: This code won't do anything useful before 5.8.3.

#! perl -slw use strict; my $s = 'the quick brown fox jumps over the lazy dog'; my @wordRefs; print do{ my $ref = \substr( $s, $-[ 0 ], $+[ 1 ] - $-[ 0 ] ); push @wordRefs, $ref; "$ref : $$ref"; } while $s =~ m[(\S+\s*)]g; print $/, '---', $/; print "$_ : $$_" for @wordRefs; __END__ P:\test>subrefs LVALUE(0x182caf8) : the LVALUE(0x1831624) : quick LVALUE(0x18315d0) : brown LVALUE(0x1824334) : fox LVALUE(0x18243f4) : jumps LVALUE(0x1831660) : over LVALUE(0x1831678) : the LVALUE(0x1831690) : lazy LVALUE(0x18316a8) : dog --- LVALUE(0x182caf8) : dog LVALUE(0x1831624) : quick LVALUE(0x18315d0) : brown LVALUE(0x1824334) : fox LVALUE(0x18243f4) : jumps LVALUE(0x1831660) : over LVALUE(0x1831678) : the LVALUE(0x1831690) : lazy LVALUE(0x18316a8) : dog

The first list is produced as the references are stacked. The second is produced from those same references. Why are they different?


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

In reply to Substr ref anomoly (revisited) by BrowserUk

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.