Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: (lemming) Comparison Of Files

by lemming (Priest)
on Dec 06, 2000 at 00:41 UTC ( [id://45080]=note: print w/replies, xml ) Need Help??


in reply to Re: Comparison Of Files
in thread Comparison Of Files

Ok. I stole a lot of the chipmunk's code (because I'm lazy and didn't want to type...). Instead, I trade speed for memory by using one hash for both old & new.

sub compare_sites { my($old, $new) = @_; if (-M $new > -M $old) { ($old, $new) = ($new, $old); } open(OLD, $old) or die "Can't open $old: $!\n"; open(NEW, $new) or die "Can't open $new: $!\n"; my %hash; my $omsk = 1; my $nmsk = 2; while (<OLD>) { chomp; $hash{$_} |= $omsk; } while (<NEW>) { chomp; $hash{$_} |= $nmsk; } close(OLD); close(NEW); for (sort keys %hash) { if ($hash{$_} == 1) { print "$_ went down overnight.\n"; } } for (sort keys %hash) { if ($hash{$_} == 2) { print "$_ went up overnight.\n"; } } } compare_sites("newsite1.txt", "newsite2.txt");
Now you could just go through the hash once and push into arrays as well, but then we might as well use the chipmunk hash. (Dance or Dish?)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://45080]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found