Ok here we go: I don't know where the +'s are coming from but they are not in the code...the red pluses that is...
#!/usr/local/bin/perl #+---------------------------------------------+ #| Configuration Options | #+---------------------------------------------+ $dirname = "C:\\Working\\"; $mastertemp = "C:\\master.txt"; $dupefile = "C:\\dupes.txt"; $newmaster = "C:\\newmaster.txt"; main(); sub main{ dirlist(); extract_data(); output_results(); } sub dirlist{ + # Pull Directory Listing opendir(DIR, $dirname) or die "can't opendir $dirname: $!"; + # open the directory while (defined($file = readdir(DIR))) { + # read the directory next if $file =~ /^\.\.?$/; push(@dirlisting, $file); # + put dirlist in @dirlisting } } sub extract_data { + # Get list of archived files %lines; %dupez; foreach (@dirlisting){ + # $filename1 = $_; open(INPUTFILE, "$dirname" . "$filename1"); open(MASTERTEMP, ">>$mastertemp"); open(DUPES, ">>$dupefile"); while (<INPUTFILE>) { $custID = substr($_,0,9); $ccn = substr($_,22,16); $expy = substr($_,44,4); $type = substr($_,50,3); $amount = substr($_,58,6); # $amount =~ s/^\s+//; if (($custID lt 0) || ($custID eq "Name ")){ }else{ dupeczech(); print MASTERTEMP "$custID"." "."$ccn"." "."$e +xpy"." "."$type"." "."$amount\n"; } } close(INPUTFILE); close(MASTERTEMP); close(DUPES); } } sub dupeczech { $lines{$ccn}++; #add one to the value if it hasn't been def +ined yet it sets it equal to 1 if($lines{$ccn} == 2){ #been seen before so add to dupes list push @dupes, $ccn; # print "$ccn $custID $lines{$ccn}\n"; # print DUPES "$custID"." "."$ccn"." "."$expy\n"; } } sub output_results { open(MASTERTEMP, "$mastertemp"); open(DUPES, ">>$dupefile"); open(NEWMASTER, ">>$newmaster"); while (<MASTERTEMP>) { $custID = substr($_,0,9); $ccn = substr($_,22,16); $expy = substr($_,44,4); $type = substr($_,50,3); $amount = substr($_,58,6); foreach (@dupes){ if ($ccn eq $_) { print DUPES "$custID"." "."$ccn"." "."$ex +py"." "."$type"." "."$amount\n"; $dupez{$ccn}++; } } if (!$dupez{$ccn}){ print NEWMASTER "$custID"." "."$ccn"." "."$ex +py"." "."$type"." "."$amount\n"; } } close(NEWMASTER); close(MASTERTEMP); close(DUPES); }

In reply to Re: Re: funny results by jspindler
in thread funny results: unexpected order reversal by jspindler

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.