in reply to Looking up elements of an array in another array!
You can try this:
I modified your OP using your description below:
Usage:your_perl_script.pl directory_to_be_checked indexDS.txt > output_file.txtuse warnings; use strict; use Cwd qw(abs_path); die "Please give the directory to the file on CLI" unless @ARGV == 2; my ( $dir, $file_to_reference ) = @ARGV; my @ds; open my $fh, '<', $file_to_reference or die "can't open file: $!"; while (<$fh>) { chomp; push @ds, $_; } close $fh or die "can't close file: $!"; $dir = abs_path($dir); chdir $dir or die "No such directory: $!"; my @result; opendir my $dh, $dir or die "can't open dir: $!"; while ( my $file = readdir $dh ) { for (@ds) { push @result, $_ if $_ eq $file; } } closedir $dh or die "can't close directory: $!"; print $_, $/ for @result;
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Looking up elements of an array in another array!
by better (Acolyte) on Mar 15, 2013 at 22:00 UTC | |
by 2teez (Vicar) on Mar 16, 2013 at 05:40 UTC | |
by better (Acolyte) on Mar 23, 2013 at 06:33 UTC | |
by tobyink (Canon) on Mar 23, 2013 at 07:05 UTC | |
by better (Acolyte) on Mar 23, 2013 at 07:50 UTC | |
|
In Section
Seekers of Perl Wisdom