in reply to finding highest and lowest number
in thread Dealing with large files in Perl

Thanking people is nice. Telling us what solution you found is even better, because it means someone else can learn from your experience.

Replies are listed 'Best First'.
Re^6: Dealing with large files in Perl
by tester786 (Initiate) on May 26, 2005 at 06:12 UTC
    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;