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

Ok, I see what you mean. I added 'use strict;' and I get...
Can't use string ("foo@bar.com") as a HASH ref while "strict refs" in +use at ./test.pl line 14.
How can I fill the values of this structure then?...
# Data Structure. #$spam_hash = { # 'email@address.com' => # { # 'Subject1' => { # cache_name1 => { # path => 'path', # from => 'from' # }, # cache_name2 => { # path => 'path', # from => 'from' # } # }, # 'Subject2' => { # cache_name1 => { # path => 'path', # from => 'from' # }, # cache_name2 => { # path => 'path', # from => 'from' # } # } #};
Until I came across a duplicated $subject, this script was working perfectly. (I guess I was getting lucky.) I need to dynamically fill the subject and cache_names to becomes slices of the email address. I'm confused on how to change my structure to one that will be functional.

Replies are listed 'Best First'.
Re: Why is part of slice duplicated?
by Abigail-II (Bishop) on May 28, 2002 at 18:01 UTC
    Well, I could give an answer and that will work, until you run into the situation you describe:
    Until I came across a duplicated $subject, this script was working perfectly.

    What do you want to do if you hit a duplicate subject?

    Abigail

      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.
        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