If you really plan on doing this in Perl your best bet would be to use the File utilities (File::Find is a fantastic thing).
However, i'd be wary of doing a backup script in perl depending on your platform. Maybe you could help us out by telling us what platform you're running on, why you chose to use perl to do this as opposed to known utilities (say tar or dump on unix) and other such useful inmformation so an answer would be a bit easier to produce...
jynx
ps This isn't meant as bad karma, just need some more info
pps And of course there's merlyn's recent post on homework that comes to mind...
| [reply] |
This is an NT based system running Active State Perl; I'll admit that
it was a pain getting some of the modules/libraries going (there is a recent
question RE the same:)
I am not compressing any data, or even tar'ring. I just want to copy unique files
from source to target. Seems to me that the Rubbish Lister was intended for this!
Thx
PH
| [reply] |
use File::Find; # these should work on any platform : )
use File::Copy;
# i'm naming your target directory hash %files,
# and the directories are $target and $source (strings)
sub checker {
return if exists %files, $_;
copy "$target$_", $File::Find::name;
}
find {wanted => \&checker}, $source;
This is the first code that pops to mind. It doesn't handle directories inside of directories well at all, but if you take a look at the File utilities you should be able to get a good feel for what it's lacking. Also, for testing if a file is the same as another, you could use File::stat which would be much more specific than just names of files. And finally, for creating the target hash structure to begin with you might want to use File::Find to help you traverse correctly down the tree. That way you don't get any infinite directories or some such nasty beasts.
find and copy do all of the grunt work here, you only need to modify the code to deal with how you laid out your hashes. It is untested, but it should work for directories that don't have any subdirectories in them.
Hope That Helps,
jynx | [reply] [d/l] [select] |