in reply to Re^3: Prototype (_)?
in thread Prototype (_)?

I wanted to write a sub that defaulted to operating upon $_ per chop, chomp and others.

The problem I had was that I tried:

sub x(_) { my $s = shift; ## make changes to $s ... }

but in the calling code, $_ remained unmodified.

As soon as I saw Corion's example above, it became obvious that when assigned to a named var, the named var held a copy rather than an alias; and that to achieve my goal, I would need to use $_[n]; just as with a normal subroutine: but not before seeing it. Silly perhaps, but ...

I think the addition of a hint about aliasing or a short, working example would strengthen the documentation and perhaps save other people the same frustration.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.