I'm trying to clean up duplicate files on my hard drive. I'm recursing through directories and saving all the file names, with data on path etc., in a hash. When a filename is already in the hash, I save its name into a second hash that holds only the dupe names. My problem is over storign the file data (more accurately, my problem is ignorance of perl data structure management ...)
Here's a snippet, showing roughly what I'm trying to do
my %fileinfo = (); # name -> (array-of-path+size+etc)
my $href = \%fileinfo;
my %dupes = (); # name->count
my $dref = \%dupes;
#------------------------
foreach # for each file, recursing through directory tree
{
# here $_ is each file name
if( exists %$href->{ $_ } ) # if filename seen already
{
%$dref->{ $_ } = 1; # then record in %dupes
}
@filedata = ( $fpath, $fsize, $fdate ); # but using real data
# this is where I'm lost -- don't know how to "savedata"
@savedata = %$href->{ $_ }; # get data data saved for filename
push @savedata, @filedata; # add new data to saved data
%$href->{ $_ } = @savedata; # put new data back in the hash
}
I want to save each file's data as an array, then add that array to the the hash. At the end of all this, for each file in the dupes, I'll get the display the array of its data, something like
myfile.mp3
c:\dir1\dir2; date=12/3/45; size=12345
c:\dir3\dir4; date=1/01/01; size=54321
Please tell me how to do the step of adding the new data, the one I've dummied as:
@savedata = %$href->{ $_ };
push @savedata, @filedata;
%$href->{ $_ } = @savedata;
(which doesn't work as I'd hoped :-( where I'd thought the @savedata would have lots of little @filedata arrays inside it ...
thanks for any advice (and hints on how to unpick the "@savedata" would be great too)