ocehb: (Default)
[personal profile] ocehb
есть 2 бесконечно больших текстовых файла отсортированных лексикографически.
Нужно найти разницу и записать в файлы.



open A, shift or die;
open B, shift or die;

my $h = 0;
while (!(eof(A) && eof(B)) ) {
    ( $a, $b ) = $h == 0 ?
        ( scalar <A>, scalar <B> ) : $h == 1 ?
        ( $a, scalar <B> ) : ( scalar <A>, $b );
    print "< $a" and next unless (defined $b);
    print "> $b" and next unless (defined $a);
    $h = $a cmp $b or next;
    print $h == 1 ? "> $b" : "< $a";
} 

в принципе, можно сократить 2 строчки, но было лень разбираться с $h = $a cmp $b or next;...

Profile

ocehb: (Default)
ocehb

January 2021

S M T W T F S
     12
345 6789
10111213141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 9th, 2026 05:16 pm
Powered by Dreamwidth Studios