Hallo, this script is thought to be a first step of building a file importing routine. But it is not (entirely) working. I have a list of IDs written into a text file. The script should scan a directory and search for alle the filenames, which contain the ID, listed in the text file. It works, if I define the array with the listed IDs directly into the script, but not, if I open and read the text file. I'm working with cygwin on WinXP

! /usr/local/bin/perl -w #Skript searches for filenames in a spec. directory #referring to a text file which contains a list of Ids $dir = $ARGV[0]; #Scan a directory and write filenames into an array opendir (SOURCE, $dir)or die "Cannot open dir: $!\n"; foreach $file (readdir SOURCE) { push (@dirFile, $file); #more than 6000 filenames } closedir SOURCE; #Open a filehandle and read a list from a text file $ref = "indexDS.txt"; open(FH, $ref) or die "Cannot open file: \n$!"; @ds = <FH>; close (FH); chomp @dirFile; chomp @ds; #Test: it works if array is defined like this: #@ds = ("I C 7702", "I C 7710", "I C 7713"); #Search for element of @ds as regex in @dirFile foreach $line (@ds) { @result = grep (/$line/, @dirFile); foreach (@result) { print "$_\n"; } }

In reply to Looking up elements of an array in another array! by better

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.