in reply to Re^4: Reassigning $_ in loop doesn't stick
in thread Reassigning $_ in loop doesn't stick

ikegami,
I thought this might be what you meant on my way home from work. I just can't think of a good reason for it. It would be quite interesting if it worked in assignment (my $alias_to_foo = grep $_, $foo;) but it doesn't. So what benefit is there that the return value is an alias into the original list?

Cheers - L~R

Replies are listed 'Best First'.
Re^6: Reassigning $_ in loop doesn't stick
by ikegami (Patriarch) on Jan 22, 2009 at 05:19 UTC
    • Efficiency (speed and memory).
    • You can pass it to for, a function, etc to be modified.
    • Use the return as an lvalue. Well, you can take a reference to it at least.
    • Simplicity. It takes extra work to make the copy.

    Mainly, I figure it just happened to work that way. And since there's no reason to change it, they decided to document it.