[tpm] how to delete a list entry from within a foreach

Jim Graham james.a.graham at gmail.com
Wed May 13 10:02:48 PDT 2009


As Uri said, try grep


DB<16> @foo = ("jim", "steve", "dave");
DB<18> @bar = grep { $_ ne "jim" } @foo;
DB<20> x @bar
0  'steve'
1  'dave'

and compare lengths of @foo and @bar to see if something got removed.

Or use a hash.

- Jim


On 13-May-09, at 12:34 PM, Fulko Hew wrote:

>
> I know this is probably simple, but I'm having a mental block,
> and I can't find the 'easy' solution in any book right now...
>
> If I'm foreach'ing over a 'pick list', I need to get a positive  
> indication
> that a match was found and then remove it from the 'pick list'.
>
> something like:
>
> if requestedvalue is on the picklist {
>    remove it from the list
>    return found
> } else {
>    return notfound
> }
>
> Being Perl, I'm sure there is an elegant way... If only I knew.
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm



More information about the toronto-pm mailing list