Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Comparison Of Files

by gaspodethewonderdog (Monk)
on Dec 05, 2000 at 20:17 UTC ( [id://45005]=note: print w/replies, xml ) Need Help??


in reply to Comparison Of Files

well this is untested code, but maybe something like this:
compare_sites("newsite1.txt", "newsite2.txt") if day eq "monday..." # psuedo code compare_sites("newsite2.txt", "newsite1.txt") if day eq "tuesday..." # psuedo code sub compare_sites { my $file1 = shift; my $file2 = shift; open IN1, $file1; while(<IN1>) { chomp; $newsite1{$_}++; } # while close IN1; open IN2, $file2; while(<IN2>) { chomp; print "$_ is a new site\n" if not defined($newsite1{$_}); } # while close IN2; } # compare_sites
Hopefully memory isn't a problem... but otherwise this shouldn't be too bad a solutions

UPDATE:

changed the code to a function as per tye's suggestion (and so he doesn't think I'm trying to make him look like an idiot I added this comment)... and added psuedo code for calling the function based on dates... :P

UPDATE:

changed the does not exist line to print the site name and not a number... plus it identifies that it is a new site...

Replies are listed 'Best First'.
Re: Re: Comparison Of Files
by runrig (Abbot) on Dec 05, 2000 at 22:47 UTC
    One thing. I would change this:
    while(<IN2>) { chomp; print "$_ is a new site\n" if not defined($newsite1{$_}); } # while
    to this:
    while(<IN2>) { chomp; print "$_ is a new site\n" unless exists $newsite1{$_}; } # while
    Checking for the existence of a key is quicker than looking up the value of a hash element.
Re: Re: Comparison Of Files
by Albannach (Monsignor) on Dec 05, 2000 at 21:06 UTC
    How about something like this to choose the order of files:
    if( -M 'newsite1.txt' > -M 'newsite2.txt' ) { compare_sites('newsite1.txt', 'newsite2.txt') } else { compare_sites('newsite2.txt', 'newsite1.txt') }
    That way if for some reason the update doesn't run one day, you'll still be comparing the files in proper order.

    --
    I'd like to be able to assign to an luser

Re: Re: Comparison Of Files
by ImpalaSS (Monk) on Dec 05, 2000 at 20:23 UTC
    Hey, i would use that kind of solution, but each file gets updates on alternating days. So on one day, newsite1.txt might be the newest file, and the other newsite2.txt might. I need a way to just see, if one name is in the other, and if its not.. print it, so if newsite2.txt has a site that newsite1.txt does not, print it, and viceversa.
    Thanks

    Dipul

      Then make it into a subroutine and reverse the arguments to it (the names of the files) depending on the day.

              - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2025-01-25 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (70 votes). Check out past polls.