Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Better way?

by Yohimbe (Pilgrim)
on Feb 16, 2001 at 09:59 UTC ( #58797=note: print w/ replies, xml ) Need Help??


in reply to Better way?

This looks like a perl based rsync(1) kind of thing.
Unless I'm horribly wrong here, this is really not that ugly. About the only thing ugly is the memory usage for the various lists. That could get big, if the file lists are long. Yours is pretty easily understood code, and unless it runs many many times a second, should not be a huge problem. But if you wanted to trim up the memory usage, perhaps looking at processing the lists sequentially, and storing only exceptions would be better/faster/more elegant.

# assuming %existing_files is a hash of existing # filenames and descriptions # and we recieve the new list of files on stdin while (<STDIN>) { chomp; if ($existing_files{$_}) { delete $existing_files{$_}; } else { $existing_files{$}="Newly Added file $_"; } } # at this point %existing_files contains the files that # should be deleted, and the newly added ones, # with the description used to differentiate them foreach (sort keys %existing_files} { if ($existing{$_} =~ /^Newly/ ) { print "Added $_;"; } else { print "Delete $_"; } }
}
--
Jay "Yohimbe" Thorne, alpha geek for UserFriendly


Comment on Re: Better way?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2014-09-19 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (133 votes), past polls