> -----Original Message-----
> From: Andre` Niel Cameron [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, December 11, 2001 9:18 AM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Array Help Please:)
>
>
> Hi,
>
> I have a prob:) I need to search threw an array and remove
> an item based on
> its name. I was thinking about maybie a for each loop but I
> am not sure how
> to go about it. Heres what I need to do:
>
> say $object= sword;
> I have an array @AllObjects('beer', 'nuts', 'sword', 'and more stuff')
> Now sword may or may not ever be in the same location of the
> array so a
> simple shift will not work here. I need to find a way to
> pull sword out of
> that array. Any help is as always greatly appreciated:)
To remove all occurences of 'sword', you can use:
$a[$_] eq 'sword' && splice(@a,$_,1) for 0..$#a;
or even
@a = grep { $_ ne 'sword' } @a;
If you're doing a lot of this kind of thing, you need to investigate
whether a hash might be a better way to store this data.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]