Carsten Hey wrote:
> +sub read_file_and_hashify {
> +     my $file = shift;
> +
> +     my ($a_ref, $h_ref) = ([], {});
> +     filemap $file, sub {
> +             push @$a_ref, $_;
> +             $h_ref->{$_} = 1;
> +     };
> +     return ($a_ref, $h_ref);
> +}

This could be written using filemap.

>  sub compare_or {
>       my ($file1, $file2) = @_;
> 
> @@ -105,8 +116,11 @@ sub compare_or {
>  sub compare_xor {
>       my ($file1, $file2) = @_;
>       
> -     compare_not($file1, $file2);
> -     compare_not($file2, $file1);
> +     my ($a1, $h1) = read_file_and_hashify $file1;
> +     my ($a2, $h2) = read_file_and_hashify $file2;
> +
> +     foreach (@$a1) { print $_, "\n" unless exists $h2->{$_} }
> +     foreach (@$a2) { print $_, "\n" unless exists $h1->{$_} }

This uses something like 4x the memory that it used before. It would be
easy to use only 3x[1]. With a good data structure, it should be
possible to only use 2x. Using an ordered hash would be one way. I have
no experience with Tie::IxHash, but it looks promising.

-- 
see shy jo

[1] get both lists,
    make second hash,
    iterate first list against second hash,
    free second hash,
    make first hash,
    drop first list,
    iterate second list against first hash

Attachment: signature.asc
Description: Digital signature

Reply via email to