in reply to Re: Re: Re: flip-flop operator and sequence number
in thread flip-flop operator and sequence number

Er, actually, I feel like a hobbit being caught red handed meddling in the affairs of wizards, which are, as everybody knows, subtle and quick to anger.

I tried and fiddle a bit with this and it's somewhat interesting. @_ is not itself aliased with the list of arguments. But each element of @_ is individually aliased with each argument. That means that you can't change the list itself (i.e. the number of its elements), but you can the values of each element. If I do:

sub { pop; shift; }->(@array);

It'll leave @array unharmed. OTOH, if I do:

sub { $_[0] = 'whatever' }->(@array);

It will change the first element of @array. You can combine both (although I would not recommend it):

sub { shift; $_[0] = 'whatever' }->(@array); # changes the *second* element of @array

--bwana147

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: flip-flop operator and sequence number
by John M. Dlugosz (Monsignor) on Jun 28, 2001 at 20:10 UTC
    Please meddle, Bilbo. I find it enlightening. A thread like this is much more interesting than just reading docs. So far I've learned:
    • Sequence Numbers: in the docs, but good refresher on how to get to them. Change loop to mid-decision test in scalar context via next/last.
    • Ending Number: will the E0 thing break in Perl 6, when it becomes 6 is true instead? Will the autotranslator handle this subtle point? Since the E0 is harmless, they should keep that for legacy, even if they add the property as well.
    • Your Sub Idiom: as noted in my node.
    • Put Real Code in Test: having a block with scratch work that returns the real result is something to keep in mind. Can't do that in C++.
    • Precidence
    • Aliasing

    —John