"I've been banging my head against a wall" and #use warnings; often go well together! Why did you turn off warnings?

if ($error == "") {

generates the warning "Argument "" isn't numeric in numeric eq (==) at ..." which would have alerted you to at least one coding error.

Oh, and I should have mentioned in reply to either of your previous posts that you should use the three parameter version of open with lexical variables for the file handle:

my $filename = "$directory\\search_results.txt"; open my $Outfile, '>', $filename or die "Can't open for writing $filen +ame - $!\n";

Generally if you need to repeated lookups the answer is to use a hash. The following (untested) code first populates a hash from the input files, then runs over the search file and generates the report file:

use strict; use warnings; my $directory = "C:\\TEMP\\files"; my %numbers; opendir my $dirScan, $directory or die "Unable to open $directory - $! +\n"; while (my $file = readdir $dirScan) { next if !-f $file or $file !~ /^R/; open my $inFile, '<', "$directory\\$file" or die "Unable to open $file - $!\n"; <$inFile>; # Skip the header line while (<$inFile>) { my @record = split /\|/, $_; next if $record[0] eq "TLR"; my $tele = substr $record[2], 3, 10; my $esn = substr $record[3], 3, 5; my $coid = substr $record[4], 3, 5; my $error = substr $record[9], 3, 3; $numbers{$tele} = {file => $file, esn => $esn, coid => $coid, error => $erro +r}; } close $inFile; } closedir $dirScan; my $filename = "$directory\\search_results.txt"; open my $outFile, '>', $filename or die "Unable to open write $filename! - $!\n"; open my $cmpFile, '<', "c:\\temp\\files\\search tns.txt" or die "Unable to open search file! $!\n"; while (<$cmpFile>) { my $target = substr $_, 0, 10; if (exists $numbers{$target}) { my %record = %{$numbers{$target}}; my ($file, $esn, $coid, $error) = @record{qw(file esn coid err +or)}; print $outFile "====TN Found====\n"; print $outFile "FILE: $file\n"; print $outFile "TN: $target\n"; print $outFile "ESN: $esn\n"; print $outFile "COID: $coid\n"; if (! $error) { print $outFile "Error: no error \n\n"; } else { print $outFile "Error: $error \n"; print $outFile "================\n\n"; } } else { print $outFile "Missing: $target\n"; } } close $cmpFile; close $outFile or die "Trouble closing the report file: $!\n";

True laziness is hard work

In reply to Re: Need Help With Loops by GrandFather
in thread Need Help With Loops by molson

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.