For an Array containing only Str elements, I can use grep(Str) in order to eliminate empty slot following a :delete;
my @prov_cd = <AB BC MB NB NL NS ON PE QC SK>; @prov_cd:delete; # Manitoba deleted @prov_cd; # [AB BC (Any) NB NL NS ON PE QC SK] my @prov_cd_cleanup = @prov_cd.grep(Str); # get rid of (Any) empty slot: [AB BC NB NL NS ON PE QC SK] @prov_cd = @prov_cd_cleanup; # [AB BC NB NL NS ON PE QC SK]
An Array can contain a variety of object types; I would prefer to "grep" everything that is not (Any).
How can I do this ?
First, note that if you remove entries via splice instead of
:delete, the items will be shifted and no 'holes' will be generate.
Now, if you truly want to filter out just
Any, you may do so via
@prov_cd.grep(* !=== Any)
However, I suspect you're looking for