anadem has asked for the wisdom of the Perl Monks concerning the following question:
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 likemy %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 }
Please tell me how to do the step of adding the new data, the one I've dummied as:myfile.mp3 c:\dir1\dir2; date=12/3/45; size=12345 c:\dir3\dir4; date=1/01/01; size=54321
(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)@savedata = %$href->{ $_ }; push @savedata, @filedata; %$href->{ $_ } = @savedata;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: data structure advice please
by clinton (Priest) on Nov 25, 2006 at 19:35 UTC | |
by Arunbear (Prior) on Nov 25, 2006 at 19:50 UTC | |
by clinton (Priest) on Nov 25, 2006 at 19:59 UTC | |
by anadem (Scribe) on Nov 25, 2006 at 21:41 UTC | |
Re: data structure advice please
by mickeyn (Priest) on Nov 25, 2006 at 20:03 UTC | |
by johngg (Canon) on Nov 25, 2006 at 23:02 UTC | |
by anadem (Scribe) on Nov 25, 2006 at 21:53 UTC |