如何在@ array2中查找值,但不在@ array1中查找值

Dea*_*ano 0 arrays algorithm perl

可能重复:
使用Perl比较两个数组

如何打印存在@array2但不存在的值@array1?例如,给定:

@array1 = qw(1234567 7665456 998889 000909);
@array2 = qw(1234567 5581445 998889 000909);
Run Code Online (Sandbox Code Playgroud)

输出应该是:

5581445 doesn't exist in array1
Run Code Online (Sandbox Code Playgroud)

dgw*_*dgw 6

my %tmp ;

# Store all entries of array2 as hashkeys (values are undef) using a hashslice
@tmp{@array2} = undef ; 

# delete all entries of array1 from hash using another hashslice
delete @tmp{@array1} ;
printf "In Array2 but not in Array1 : %s\n" , join( ',' , keys %tmp ) ;
Run Code Online (Sandbox Code Playgroud)