in reply to Seeking guidance on how to approach a task
Since I usually get passed excel files, I haven't had the occassion to work with 190,000 line files. I haven't had any slowness issues, though.#! perl -w use strict; my ($file, $col, $file2, $col2) = @ARGV; my (%unique, %unique2); my @column; my ($x, $header); my @fields; # I put something like this in all my scripts so I don't need to remem +ber argument order if ($file eq "?"){ die "usage: compcolumns.pl file1 column1 file2 column2\n"; } ## whenever you open a file, do yourself a favor and tell yourself if +it doesn't open open FIL, $file or die "Could not open $file: $!\n"; $x = 0; %unique=(); while (<FIL>){ chomp; ##The split here, a regular expression, is what you would chan +ge (at least if your data is based on space delimiting instead of tab +-delimiting). @fields = split /\t/; if (defined ($fields[$col]) ){ $header = $fields[$col] if $x == 0; $unique{$fields[$col]}++; } else{ $unique{"BLANK"}++; $header = "BLANK"; } $x++; } open FIL, $file2 or die "Could not open $file2: $!\n"; $x=0; while (<FIL>){ chomp; @fields = split /\t/; if (defined ($fields[$col2]) ){ $header = $fields[$col2] if $x == 0; $unique2{$fields[$col2]}++; } else{ $unique2{"BLANK"}++; $header = "BLANK"; } $x++; } ## The output routine. Note that if something's in both files, it wil +l be printed twice. foreach (sort keys %unique) { if (!exists $unique2{$_}){ print "$_ in $file but not $file2\n"; } else { print "$_ in both files\n"; } } foreach (sort keys %unique2) { if (!exists $unique{$_}){ print "$_ in $file2 but not $file\n"; } else { print "$_ in both files\n"; } }
|
|---|