Hi monks, haven't been on in awhile and haven't posted in an even longer while. Having trouble with a hash slice. Somehow I'm duplicating a slice of data, but have no idea how I'm doing it. Here's the relevant code...
$to = "foo\@bar.com"; $subject = "New CDs now"; $file_name = "AAAAA.txt"; $from = "that\@person.com"; $last_dir = "Spam"; $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; $to = "foo2\@bar.com"; $subject = "New CDs now"; $file_name = "BBBBB.txt"; $from = "that2\@person.com"; $last_dir = "Spam"; $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; print "\n"; for my $email_slice (sort keys %{$spam}) { print "email_slice - $email_slice\n"; for my $subject_slice (sort keys %{$email_slice}) { print "subject_slice - $subject_slice\n"; for my $fn_slice (sort keys %{$subject_slice}) { print "fn_slice - $fn_slice\n"; } } print "\n"; }
Sorry for the sloppy code, however, this comes from a very large script and just to figure this part out I wrote this code into a separate smaller script for debugging.
Most of you should be able to just paste this code into a vi session and run it, nothing special. Here's the output...
email_slice - foo2@bar.com subject_slice - New CDs now fn_slice - AAAAA.txt fn_slice - BBBBB.txt email_slice - foo@bar.com subject_slice - New CDs now fn_slice - AAAAA.txt fn_slice - BBBBB.txt
Notice how the fn_slice is duplicated? What I'm trying to get is...
email_slice - foo2@bar.com subject_slice - New CDs now fn_slice - BBBBB.txt email_slice - foo@bar.com subject_slice - New CDs now fn_slice - AAAAA.txt
Notice how the AAAAA.txt and BBBBB.txt are separated by their respective email addresses? I can not imagine how the fn_slice is getting duplicated? I think it has something to do with the $subject since it's the same, however, the email_slice should take care of that and separate it.

Thank you monks for your help, AGAIN! :)

In reply to Why is part of slice duplicated? by the_0ne

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.