On Thu, Oct 18, 2001 at 05:24:51PM -0400, Andrew Stanley wrote:
> I have the following piece of code:
> 
> my %self;
> 
> $self->{txnType} = "foo";
> my @orderedRecordTypes = qw(bar baz zed);
> my @files = qw(\\should\\not\\pass \\should\\pass\foo_bar
> \\should\\pass\\foo_zed \\shouldnt\\pass\\at\\all);
> 
> @orderedFiles = map {
>       my $txnTypeRecType = $self->{txnType} . "_" . $_;
> 
>       map {
>               $_ if (split(/\\/))[$#_] =~ /^$txnTypeRecType/io;
>       } @files;               
> 
> } @orderedRecordTypes;
> 
> print "Passed:\n".join("::", @orderedFiles);
> 
> Problem is, @orderedFiles will contain a bunch of undef's inside of it.
> How can I prevent it from happening?  I can always filter @orderedFiles
> after... but I feel that there is some way that I'm missing.

Instead of if, use ?:, and return an empty list for items that you want
skipped.


@orderedFiles = map {
      my $txnTypeRecType = $self->{txnType} . "_" . $_;

      map {
              (split(/\\/))[$#_] =~ /^$txnTypeRecType/io ? $_ : ();
      } @files;

} @orderedRecordTypes;


Ronald

Reply via email to