You're getting a bit mixed up with all the sigils (%@$). First, there's no need to do this:

my %dupes = (); # name->count my $dref = \%dupes;

You can, but there is no need. And in this case you're not passing the hash around, so I've left it as a hash, rather than a hash-ref.

Where you DO need a ref is where you store the filedata in %fileinfo. You want an array containing all the files with name X, and you store an array as a hash value by using an array ref.

@file_info = qw(data1 data2 data3); %files = ( X => \@file_info )

If you want to add something to the array, then you need to use push, which means you need an array, not an array ref, so you need to dereference it:

$file_info_ref = $files{X}; push @$file_info_ref,'data5'; or push @{$files{X}}, 'data5'

So:

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 }

In reply to Re: data structure advice please by clinton
in thread data structure advice please by anadem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.