in reply to Re: Why is part of slice duplicated?
in thread Why is part of slice duplicated?

Basicly I just want everything "grouped, if you will" by email address and then by subject, so from this...
$to = "foo\@bar.com"; $subject = "New CDs now"; $file_name = "AAAAA.txt"; $from = "that\@person.com"; $last_dir = "Spam"; $to = "foo\@bar.com"; $subject = "New CDs now"; $file_name = "CCCCC.txt"; $from = "that\@person.com"; $last_dir = "Spam"; $to = "foo2\@bar.com"; $subject = "New CDs now"; $file_name = "BBBBB.txt"; $from = "that\@person.com"; $last_dir = "Spam"; $to = "foo3\@bar.com"; $subject = "New CDs now"; $file_name = "DDDDD.txt"; $from = "that\@person.com"; $last_dir = "Spam";
I'd like to get this...
email_slice - foo@bar.com subject_slice - New CDs now fn_slice - AAAAA.txt fn_slice - CCCCC.txt email_slice - foo2@bar.com subject_slice - New CDs now fn_slice - BBBBB.txt email_slice - foo3@bar.com subject_slice - New CDs now fn_slice - DDDDD.txt
So, even if a subject is duplicated several times, if it matches with the email address, it will be grouped with that same one. Then the file names will group right along with because they are linked to the subject.

Thanks again.

Replies are listed 'Best First'.
Re: Why is part of slice duplicated?
by Abigail-II (Bishop) on May 28, 2002 at 18:37 UTC
    Do something like:
    sub add { my ($hashref, $to, $subject, $file_name, $from, $last_dir) = @_; $hashref -> {$to} ||= { }; $hashref -> {$to} {$subject} ||= [ ]; push @{$hashref -> {$to} {$subject}} => {$file_name => {path => $last_dir, from => $from}}; }
    And call it like:
    add $spam, 'foo@bar.com', 'New CDs now', 'AAAAA.txt', 'that@person.com +', 'Spam';

    Abigail

      Wow, that's exactly what I needed and it works perfectly also. Need to get back to the books on advanced data structures now. Also have a lot of changing to do to the larger script that is based on this structure

      Thank you very much for your help. Wish I could give more than one ++ for this reply.