fork download
  1. #!/usr/bin/perl
  2. # your code goes here
  3. my @array1 = ( 1, 2, 3, 4, 5, 6, 7, 8, 9 ) ;
  4. my @array2 = ( 3, 5, 7, 11, 13, 15 ) ;
  5. my %tmp ;
  6.  
  7. # Store all entries of array2 as hashkeys (values are undef) using a hashslice
  8. @tmp{@array1} = undef ;
  9.  
  10. # delete all entries of array1 from hash using another hashslice
  11. delete @tmp{@array2} ;
  12. printf "In Array1 but not in Array2 : %s\n" , join( ',' , keys %tmp ) ;
Success #stdin #stdout 0s 3564KB
stdin
Standard input is empty
stdout
In Array1 but not in Array2 : 6,9,2,8,1,4