develooper Front page | perl.perl5.porters | Postings from October 2009

Re: "If" your subscript goes bump in the night

Thread Previous
From:
Tom Christiansen
Date:
October 31, 2009 10:40
Subject:
Re: "If" your subscript goes bump in the night
Message ID:
27594.1257010799@chthon
Yves wrote:

> Ah sorry, I misunderstood. And thus if I understand
> correctly that it is to you who we owe:

>   $hash->{foo}{bar}{baz}

> then I thank you. A lot. :-)

Yep, and you're welcome.

I found it worth the yacc complaints, given how noisy 
multiply subscripted data structures become without it.
Maybe it had bad side-effects, though I don't remember 
any being ever directly tied to that change.

Much later, somebody else did the ->() hack.

I don't like tangling with the parser; I think that's the 
only time I messed with it.  Other patches I recall doing
were more platform-specific, like quad support and a bit 
of checkpoint/restart in dump().

There are probably people reading this who are younger than 
those patches are.  Gives one a bit of temporal vertigo.

BTW, I notice B::Deparse doesn't seem to be consistent about 
filling in the arrow:

    % perl -MO=Deparse -e '$x[4] = sub {"surprise"}; print $x[4]()'
    $x[4] = sub {
	'surprise';
    }
    ;
    print $x[4]->();
    -e syntax OK

That had an arrow printed as I expected.  

  ( That's the funny A->B arrow that means &{A}B for when B 
    starts with a round bracket, not the normal one that 
    means ${A}B for when B starts with a square or curly bracket. )

But curiously, this one does not:

    % perl -MO=Deparse -e '$x{fred} = sub {"surprise"}; print $x{fred}()'
    $x{'fred'} = sub {
	'surprise';
    }
    ;
    print $x{'fred'}();
    -e syntax OK

Neither arrow gets printed here, and adding -x=9 doesn't change this:

    % perl -MO=Deparse -e '$x[4]{fred} = sub {"surprise"}; print $x[4]{fred}()'
    $x[4]{'fred'} = sub {
	'surprise';
    }
    ;
    print $x[4]{'fred'}();
    -e syntax OK

    % perl -le '$x[4]{fred} = sub {"surprise"}; print $x[4]{fred}()'
    surprise

I half-expected there to be an option to get it to spit out:

    ${$x[4]}{fred} = sub {"surprise"}; 
    print &{${$x[4]}{fred}}();

:)

--tom

Thread Previous


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