in reply to Grep question

Yes, though I'm not sure I'd recommend it over the other solutions posted:
@statusoption = splice(@statusoption, (grep $statusoption[$_] eq $status, 0..$#statusoption)[0]);
Update: No need for splice when you just want a slice:
@statusoption = @statusoption[ (grep {$status eq $statusoption[$_]} 0..$#statusoption)[0] ..$#statusoption];
Update: But splice is better than reassignment:
splice(@statusoption, 0, (grep $status eq $statusoption[$_], 0..$#stat +usoption)[0]);
Here's one that will short-circuit :-D:
splice(@statusoption, 0, &{sub { grep {$status eq $statusoption[$_] and return $_} 0..$#statusop +tion }} );

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Grep question
by hok_si_la (Curate) on Feb 03, 2005 at 18:12 UTC
    Thanks all of you. I have made the suggested changes. I will need to look at them more in depth.

    I have a similar question for those of you with patience. I am trying to remove an item from an array using the delete function. Here is the code:
    @statusoption = ('Waiting Approval' , 'Denied' , 'Approved' , 'Ordered +' , 'Building' , 'Built' , 'Shipped'); delete $statusoption[3];
    This simply yields ('Waiting Approval' , 'Denied' , 'Approved' , '' , 'Building' , 'Built' , 'Shipped')
    I would like to remove 'Ordered' from the array and shift all the other elements down an index truncating the array by 1.

    I appreciate you help,
    hok_si_la
      That's what splice is for:
      splice(@statusoption, 3, 1);

      Caution: Contents may have been coded under pressure.
        Ahhhhhhh! Thanks, you have been most helpful. Have a good super bowl weekend if you are in to that kind of thing.