in reply to Re^4: Compare 2 arrays
in thread Compare 2 arrays
Your code:#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %keepList; while (my $line = <DATA>) { my $sdf_file; next unless ($sdf_file) = $line =~ /([\w ]+\.nfo)/; $keepList{$sdf_file} = 1; print "keeping \"$sdf_file\"\n"; #update for debugging ####### } =example printout keeping "filename1.nfo" keeping "filename2.nfo" keeping "file name2.nfo" keeping "file name3.nfo" keeping "file name4.nfo" =cut __DATA__ fullpath="C:\directory\filename1.nfo" id="1a" fullpath="C:\directory\filename2.nfo" id = "nonsense" fullpath = "C:\directory\file name2.nfo" fullpath = "C:/directory/file name3.nfo" fullpath = "C:\directory/file name4.nfo"
better written? as:my @files = $files; opendir(OUTPUT, $files); @files = grep {$_ ne '.' and $_ ne '..'} readdir(OUTPUT); closedir(OUTPUT);
The -f file test excludes not only the "." and ".." directories but also other ones that might exist.opendir(OUTPUT, $files) or die "unable to opendir $!"; my @files = grep {-f $files/$_} readdir(OUTPUT); closedir(OUTPUT);
Overall, great job at getting something to "work". In the scheme of things, my comments are just nits.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Compare 2 arrays
by Anonymous Monk on Jul 01, 2016 at 17:43 UTC |