There's no need to pipe cat into your filehandles as you can open files directly; the three-argument form with lexical filehandles is recommended practice.

Instead of

open IN1,"cat $DATA_DIR/$INFILE_NAME |" or die "Can't open $INFILE_NAM +E: $!\n";

do

open my $in1FH, q{<}, $DATA_DIR/$INFILE_NAME or die qq{Can't open $INFILE_NAME: $!\n};

As you suspected, you are not reading the numbers file correctly. From your original post it looks like you have 5000 or so numbers in a file, one per line. If you assign the readline into an array rather than a scalar then the whole file is read into the array, one line per element. Furthermore, chomping an array will remove the line terminator from every element in the array. You could read the file line by line in a while loop instead if you like but then you would have to push each line onto the array. These two bits of code are equivalent.

Using a loop

my @numbers = (); while( <$in1FH> ) { chomp; push @numbers, $_; }

Reading directly into an array.

chomp( my @numbers = <$in1FH> );

You have removed the bare code block around the reading of the second file. It was there so that the local $/ ... really was localised to that scope to avoid possible side effects later in your script. Since you have a lot of files to read you could perhaps do something like

my @filesToRead = ( populate this list somehow ); ... foreach my $file ( @filesToRead ) { open my $in2FH, q{<}, $file or die qq{Can't open $file: $!\n}; local $/ = qq{</DU>\n}; while( <$in2FH> ) { ... } close $in2FH or die qq{Can't close $file: $!\n}; }

I hope this is helpful.

Cheers,

JohnGG


In reply to Re^3: Match a list of numbers from a list of files by johngg
in thread Match a list of numbers from a list of files by shawshankred

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.