my %dupes = (); # name->count
my $dref = \%dupes;
####
@file_info = qw(data1 data2 data3);
%files = (
X => \@file_info
)
####
$file_info_ref = $files{X};
push @$file_info_ref,'data5';
or
push @{$files{X}}, 'data5'
####
my %fileinfo;
my %dupes;
# for each file, recursing through directory tree
foreach {
# here $_ is each file name
# if filename seen already
if( exists $fileinfo{$_} ) {
# then record in %dupes
$dupes{$_} = 1;
}
@filedata = ( $fpath, $fsize, $fdate ); # but using real data
# if fileinfo doesn't yet have an entry for this $_,
# then assign an empty array ref
# saved_info is now an array ref which is
# also stored in $fileinfo{$_}
$saved_info = $fileinfo{$_} ||= [];
push @$saved_info,\@filedata;
# No need to re-store it in the hash, because $fileinfo{$_}
# and $saved_info both point to the same array
}