Certainly... I should have done that..

#!/usr/bin/perl

&processf();
use Fcntl ':flock';

sub processf() {

unless (open(FILER, "ts-speed.txt")) {
die ("cannot open input file out2\n");
}

$newfile="final.out";

flock FILE, LOCK_SH;


while ($line=<FILER>) { # first loop starts here..
chomp($line);
my $mymac = substr($line, 0, 12);
unless (open(FILER2, "docsis-file-orig")) {
die ("cannot open input file out1\n");
}

while ($item=<FILER2>) { # second loop starts here....
chomp ($item);
$mymac1 = substr($item, 0, 12);
if ($mymac =~ /^$mymac1$+/g) {
unless (open(FILEW, ">>$newfile")) {
die ("cannot open input file newfile\n");
}
flock(FILEW, 2); # file lock set
printf("'%s' and '%s' are identical\n", $mymac, $mymac1);
print FILEW ("$item $line\n");
flock(FILEW, 8); # file lock unset
close(FILEW);
} #if end here;
} #while second end here;
close(FILER2);


} #while first end here;


close(FILER);
} #sub end here;


In reply to Re^6: Dealing with large files in Perl by tester786
in thread Dealing with large files in Perl by tester786

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.