in reply to comparing two arrays

use Fatal qw/open/; my %h; open my $fh, '<', '/tmp/file1'; while ( defined ($_ = <$fh>)){ /^([\d.]+)/ and $h{$1}++; } open $fh, '<', '/tmp/file2'; while ( defined ($_ = <$fh>)){ /^([\d.]+)/ and delete $h{$1}; } print join "\n", keys %h;
Boris

Replies are listed 'Best First'.
Re^2: comparing two arrays
by GrandFather (Saint) on Oct 20, 2005 at 18:16 UTC

    Consider:

    file1 6.66 6.75 6.75 6.66 6.75 6.75 7.17 7.17 7.31 7.31 7.41 7.41 file2 6.75 6.66 6.75 6.75 7.17 7.17 7.31 7.31 7.41 7.41 6.62 6.75

    which should generate:

    6.62 6.66

    Perl is Huffman encoded by design.
      Upps, you are so right.
      use Fatal qw/open/; my ( %h, %g ); open my $fh, '<', '/tmp/file1'; while ( defined ($_ = <$fh>)){ /^([\d\.]+)/ and $h{$1}++; } open $fh, '<', '/tmp/file2'; while ( defined ($_ = <$fh>)){ /^([\d\.]+)/ and $g{$1}++; } my @k = keys %h; delete @h{keys %g}; delete @g{@k}; print join "\n",( keys %h, keys %g );
      Boris
Re^2: comparing two arrays
by Anonymous Monk on Oct 20, 2005 at 10:41 UTC
    thanks for getting me started