in reply to Array slice vs foreach and push

Not an answer to your splice question, but this seems a good deal more straightforward... if it fits your "realworld application."
#!/usr/bin/perl use Modern::Perl; # 937262 my @chars = qw( a b c ? : ! f g ); my @newchars = (); for my $char(@chars) { if ($char =~ /[[:alpha:]]/ ) { # posix: letters. cf alts for + unicode "Properties" usage push @newchars, uc($char); }else{ push @newchars, $char; } } for my $newchar(@newchars) { print $newchar . " "; # A B C ? : ! F G }

Replies are listed 'Best First'.
Re^2: Array slice vs foreach and push
by chrisburel (Initiate) on Nov 10, 2011 at 02:37 UTC

    Unfortunately, that doesn't fit the real world application. I'll give a bit more context.

    What I have is an array of objects. Each of these objects have a version property. Each object also has a few associated special versions, like one called the official version. Then there's a method that takes an array of these objects and returns an array of these special versions, called getOfficialVersions. But not all objects have an official version, so in that case the method returns an undef for that index in the array. So I'm looking for a quick way to get the list of objects from the input list that have an undef in the array returned from getOfficialVersions.

      if that case, perhaps you should be thinking about using some aspect of ...
       if (defined)