in reply to Find array duplicates

Before I loose any more reputation points. I was envisaging something like this:
sub Check_excluded_tables_list (@) { @tables = @_; @Excluded_tables = qw/Table_A/; foreach (@tables){ $table_name = $_; if ($table_name =~ @Excluded_tables){ $table_name = ""; } else{ # do nothing } push (@list_of_accepted_tables, $table_name); } #close list of all table names if (@tables = @list_of_accepted_tables){ $status = "good"; } else{ $status = "bad"; } }

I haven't had time to test this code yet.

Replies are listed 'Best First'.
Re: Re: Find array duplicates
by duff (Parson) on Nov 11, 2003 at 18:30 UTC

    How about this?

    sub checkxtlist (@) { my @Excluded = qw(Table_A Table_B); my %Excludes = map { $_ => 1 } @Excluded; my @Accepted = grep { !$Excludes{$_} } @_; my $status = (@_ == @Accepted) ? "good" : "bad"; }
    Of course, you probably don't want to hard code the list of excluded tables in the subroutine (I don't know though, you might). And I'm not sure why you want a prototype on this subroutine either.

    Also, if you wanted to exclude by regular expression, you could do that too without much difficulty:

    sub checkxtpatlist ($@) { my $pat = shift; my @Accepted = grep { !/$pat/ } @_; return my $status = (@_ == @Accepted) ? "good" : "bad"; } my $s = checkxtpatlist(qr/Table_[ABC]/,@tables);