develooper Front page | perl.perl5.porters | Postings from November 1999

possible bug: lvalue substr

From:
Hugo
Date:
November 4, 1999 20:59
Subject:
possible bug: lvalue substr
Message ID:
199911050501.FAA16291@crypt.compulink.co.uk
With perl in qw(5.004_05 5.005 5.005_01 5.005_02 5.005_03 5.005_56 5.005_57
5.005_61 5.005_62), I get this:

crypt% perl -wle 'for(@ARGV){ for(substr $_, 0){ s/(.)/$1$1/; print }} print @ARGV' test
ttes
ttest
crypt% 

.. whereas with 5.003_97 and 5.004 I get:
ttest
ttest
.. as expected. Or as I think is expected.

I suspect this is due to the change in 5.004_05 and 5.005 to 'make magical
lvalues more magical'. I don't know whether this particular behaviour should
be considered a bug or not; certainly it is rather inconvenient here, since
the ability to modify and then see the modified value of an lvalue substr
would be ideal for my current task, actual code:

    for (substr($t, $o)) {
        s/^(${lastdigit}*)(.)?/ (0 x length $1) . ($2 + 1) /e;
        $s += tr/$digit/$digit/ * $p + $o * ($p / $base);
    }

(except that $digit has been evalled into place).

Possible references: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/
  1998-04/msg00035.html 1998-04/msg00115.html 1998-07/msg02387.html
and the thread starting 1998-03/msg01839.html and continuing the
following month at 1998-04/msg00139.html.

Hugo



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About