http://www.perlmonks.org?node_id=1023563


in reply to Looking up elements of an array in another array!


#!/usr/bin/perl --
use strict; use warnings;
use autodie;
use File::Find::Rule;
use File::Slurp;
my $startdir = shift or die Usage();
my $fnames = join '|', map quotemeta, read_file('indexDS.txt' , qw/ chomp 1 /);
my @fnames = find( file => name => qr{$fnames}, in => $startdir );
print "$_\n" for @fnames;

Replies are listed 'Best First'.
Re^2: Looking up elements of an array in another array!
by better (Acolyte) on Mar 14, 2013 at 22:23 UTC

    Hi Anonymus Monk, thank you very much for your fast reply!

    As you might already guessed, your script gives me a really tough nut to crack. Anyway! I tried 'paste and copy' and got an error message, that Find/File/Rule.pm is not included in @INC.... So I will find out, how I can fix this problem. Thanks again. I'll come back and report

    better

      got an error message, that Find/File/Rule.pm is not included in @INC.... So I will find out, how I can fix this problem.
      If you want to use File::Find::Rule, you need to install it. cpan is one way.

        Thanks to toolic! Cpan works really nice

        best

        Hi Anonymus Monk,

        OK! I installed two missing modules und executed your script. I almost thought it works fine, because no error meassages appeared. But it ended without showing any results. Any idea what went wrong???

        best

        b

Re^2: Looking up elements of an array in another array!
by better (Acolyte) on Mar 15, 2013 at 21:42 UTC

    Hi Anonymous Monk,

    as none of the proposals worked for me, I started wondering, why? The clue seems to be the text file, which serves as a reference. I created it by copying a coloumn out of an excel worksheet into a notepad file. After I created a new text file with perl your script worked perfectly well. It seems that "Copy and Paste" from microsoft excel has caused the trouble.

    Now I will add the next step, which is copying the matching files into another directory

    Thanks again

    better

        Hi Anonymous Monk,

        after playing around a little with different scripts, and learning about the use of modules in perl, I added a line into your script to achieve my aim of creating a file importer.

        The job is almost done.

        It works fine, if I create the text file 'indexDS.txt' via perl. The problem I couldn't solve, is that, as soon as I change the text file by opening with notepad (windows), it crashes. I tried to implement ':encoding(utf8)'. Without success.

        At least I managed to parse the original excel file (with all the IDs in the first coloumn) and convert it into a text file using encoding(utf8). But this converted text file doesn't work with this script. Anyhow, I am sure, it would be much nicer, if I could parse the CVS file directly into that script

        But how?

        Sorry, I can't get any further on my own.

        better

        P.S: This is what I added to your script

        use File::Basename; use File::Copy; ... ... ... ... my $dirTarget = '/cygdrive/d/tmp/'; copy ($_, $dirTarget.basename ("$_")) for (@fnames);

        The scripts works now! It was not the encoding, but the carriage return, which was included in the "bad" text file. Monk McA came up with reading the text file in a hex code. After stripping of the carriage return from each ID, the IDs could be handed over as regex into your code. And voilą, a couple of thousand files had been found and copied.

        Thanks again! That saved me a lot of time.

        I'm feeling much

        better ;-)