in reply to Why is part of slice duplicated?

$spam->{$to} = $to; $spam->{$to}->{$subject} = $subject; $spam->{$to}->{$subject}->{$file_name} = $file_name; $spam->{$to}->{$subject}->{$file_name}->{'path'} = $last_dir; $spam->{$to}->{$subject}->{$file_name}->{'from'} = $from;

You are doing some very fishy stuff here, which use strict; would not have allowed you to. First you set $spam->{$to} to $to, which is a string. But then, in the next line, with $spam->{$to}->{$subject}, you are treating it as a hashreference! And later on, you are doing the same trick with $subject and $file_name.

You should use Data::Dumper and display the context of $spam. You will be surprised what it contains (or rather, what it doesn't contain).

Remember, unless you know what you are doing, always use strict;.

Abigail

Replies are listed 'Best First'.
Re: Re: Why is part of slice duplicated?
by the_0ne (Pilgrim) on May 28, 2002 at 17:48 UTC
    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.
      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.