On Mon, Jun 14, 2004 at 06:05:10PM -0400, Mark J. Reed wrote:
:
: On 2004-06-14 at 22:58:58, Matthew Walton wrote:
: > 'it would be better to explicitly just say
: >
: > (@list.grep value) = undef
: >
: > although I think that might be supposed to be
: >
: > (@list.grep value) �= undef;
:
: Those do different things according to my understanding. The first
: removes all matching items from the list; the second replaces the
: matching items with undef.
:
: e.g. (please forgive any Perl6 syntax errors):
:
: [1,2,3,4,5].grep { $_ % 2 } = undef
:
: results in the list
:
: [2,4]
:
: while
:
: [1,2,3,4,5].grep { $_ % 2 } �= undef
:
: results in the list
:
: [undef, 2, undef, 4, undef]
Er, no. Assignment of undef to a scalar value does not imply that it
is deleted from its current location (or locations). Scalars don't
necessarily even know what their locations are. Deletions are necessarily
a transaction with the container object, and by the time you've done a
grep, you've thrown away the reference to the container object. Even
if that were not the case (and a grep method could certainly be taught
to be an lvalue), assigning undef would at most undefine the selected
scalar values in place, because undef is a scalar value, not a list,
and because all of these are the same value as far as list assignment
is concerned:
()
(undef)
(undef, undef)
(undef, undef, undef)
...
I think you're looking for something more like
@list.=grep { not $_ % 2 };
But it doesn't make much sense to do that to an anonymous list.
Larry