Andrew Stanley <[EMAIL PROTECTED]> said something to this effect on 10/18/2001:
> 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.

Add a grep in there:

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 = grep !/^$/, map {
                ^^^^^^^^^^^
  my $txnTypeRecType = $self->{txnType} . "_" . $_;

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

} @orderedRecordTypes;

print "Passed:\n".join("::", @orderedFiles);

This gives me the right answer.

(darren)

-- 
We are not who we think we are. We are not who others think we are.
We are who we think others think we are.
    -- Anonymous

Reply via email to