从Perl中的另一个数组中删除一个数组中的元素

and*_*ers 2 perl

我想将所有元素都用大写字母表示,将它们存储在数组中,然后从该数组中删除符号链接。问题是我不知道如何删除一个数组中包含在另一个数组中的所有元素,因为我是perl的新手。

到目前为止,贝娄是我的代码。

foreach ${dir} (@{code_vob_list}) 
{
    ${dir} =~ s/\n//;
    open(FIND_FILES, "$cleartool find ${dir} -type f -exec 'echo \$CLEARCASE_PN' |") or die "Can't stat cleartool or execute : $!\n"; #This command gets all files
    @{files_found} = <FIND_FILES>;

    open(SYMBOLIC_FIND_FILES, "$cleartool find ${dir} -type l -exec 'echo \$CLEARCASE_PN' |") or die "Can't stat cleartool or execute : $!\n"; #This command get all symbolic links
    @{symbolic_files_found} = <SYMBOLIC_FIND_FILES>;
    #Filter away all strings contained in @{symbolic_files_found} from @{files_found}
    foreach my ${file} (@{files_found}) 
    {
        #Here I will perform my actions on @{files_found} that not contains any symbolic link paths from @{symbolic_files_found}
    }
}
Run Code Online (Sandbox Code Playgroud)

提前致谢

cho*_*oba 7

要过滤数组,可以使用grep

my @nonlinks = grep { my $f = $_;
                      ! grep $_ eq $f, @symbolic_files_found }
               @files_found;
Run Code Online (Sandbox Code Playgroud)

但是使用哈希通常更干净。

my %files;
@files{ @files_found } = ();            # All files are the keys.
delete @files{ @symbolic_files_found }; # Remove the links.
my @nonlinks = keys %files;
Run Code Online (Sandbox Code Playgroud)