in reply to Re: Perl Syntax that we generally don't know or forget.
in thread Perl Syntax/resources that we generally don't know or forget.

No! Don't stop there! You can also use the lvalue bindings of argument passing! Three nested lvalue usages:
my $value = "abcde"; sub attack { $_[0] = "x" } attack($_) for substr($value, 2, 1); print "$value\n"; # prints "abxde\n"
And if I understood lvalue subroutines better, I could probably write "attack($_) = 'x'" instead, for a fourth layer. {grin}

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Re: Perl Syntax that we generally don't know or forget.
by shotgunefx (Parson) on Jan 18, 2004 at 18:15 UTC
    Like this?. Or is there something I'm missing here..
    sub attack :lvalue { substr($_[0], 2, 1) ; }

    -Lee

    "To be civilized is to deny one's nature."
      That is supposed to work, but currently has some problems (see perl bug #24200) if you call attack in an rvalue context after calling it in an lvalue context.