in reply to Re^3: Compare 2 arrays
in thread Compare 2 arrays
Hi Marshall,
Thanks! That does work! With the help of my co-worker, we refined it a little more by including white spaces in search.
Thank you all who have helped me with my problem.
Below is what we came up with.
#!\perl\bin\perl use strict; use warnings; my $files = "C:/Directory"; my $list = "C:/Test.sdf"; open my $name, '<', $list or die "Failed to open file: $!\n"; my @files = $files; opendir(OUTPUT, $files); @files = grep {$_ ne '.' and $_ ne '..'} readdir(OUTPUT); closedir(OUTPUT); my %wanted_files; while (<$name>) { if ($_ =~ /^\s*fullpath=.*[\\\/](\w+\.nfo)"/) { $wanted_files{$1} = 1; } } foreach my $target_file (@files) { if (not $wanted_files{$target_file}) { unlink($files . "/" . $target_file) or die $!; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Compare 2 arrays
by Marshall (Canon) on Jun 30, 2016 at 00:01 UTC | |
by Anonymous Monk on Jul 01, 2016 at 17:43 UTC |