develooper Front page | perl.perl5.porters | Postings from March 2000

:lvalue bug

Thread Previous | Thread Next
From:
Tom Christiansen
Date:
March 22, 2000 06:52
Subject:
:lvalue bug
Message ID:
4877.953736721@chthon
I wonder why this works:

    our $var = 1;
    sub frob : lvalue { $var } 
    $i = 0;
    for my $naughty ( frob(), frob(), frob() ) {
	$naughty = "sneaky" . ++$i;
    } 
    print "var now $var\n";

And so does this:

    substr(frob(), 3, 0) = "WOW";
    print "var now $var\n";

But this doesn't:

    sub prepend :lvalue { substr($_[0], 0, 0) }
    $name = "thingie";
    prepend $thingie = "once";
    print "thingie now $thingie\n";

That prints "once", not "oncethingie".

I also wonder why these all produce the same effect:


    sub prepend :lvalue { \substr($_[0], 0, 0) }
    sub prepend :lvalue { \\substr($_[0], 0, 0) }
    sub prepend :lvalue { \\\substr($_[0], 0, 0) }
    sub prepend :lvalue { \\\\substr($_[0], 0, 0) }
    sub prepend :lvalue { \\\\\substr($_[0], 0, 0) }
    sub prepend :lvalue { \\\\\\substr($_[0], 0, 0) }
    sub prepend :lvalue { \\\\\\\substr($_[0], 0, 0) }
    sub prepend :lvalue { \\\\\\\\substr($_[0], 0, 0) }
    sub prepend :lvalue { \\\\\\\\\substr($_[0], 0, 0) }
    sub prepend :lvalue { \\\\\\\\\\substr($_[0], 0, 0) }
    sub prepend :lvalue { \\\\\\\\\\\substr($_[0], 0, 0) }

And so on, ad infinitum.

--tom

Thread Previous | Thread Next


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