I'm having trouble understanding why when the following code is executed, only the last item in the DATA appears in the hash.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper::Simple; my @array; my %hash; while(<DATA>){ chomp; @array = split /\s+\s+/, $_; %hash = ($array[0] => {$array[1] => $array[2]}); } print Dumper (%hash); __DATA__ susan anus@delta.co.th cannot find you +r hostname jennifer r_curran@ntnu.no cannot find you +r hostname jennifer jones@bol.net.in cannot find you +r hostname jennifer millionairemaker@freshcornam.com cannot find you +r hostname tim millionairemaker@freshcornam.com cannot find you +r hostname jennifer cmayer@kareltek.fi cannot find you +r hostname jack ictiplo@tiplo.com.tw cannot find you +r hostname russ orders@koss.com Host not found clara Sandra@camrpc.com Host not found jennifer Warranty@onlogixx.com cannot find you +r hostname employment elitemate@rllformat.com cannot find you +r hostname jack JHuffman@pulsetech.net cannot find you +r hostname clara Sandra@camrpc.com Host not found susan linda@kepro.com.tw cannot find you +r hostname jobs kwillis@cors.com Host not found employment LifeShopDirect@freshcornam.com Host not found
When executed, only the last item appears in the hash.

%hash = ( 'employment' => { 'LifeShopDirect@freshcornam.com' => 'Host +not found' } );
Thanks,
Mike

Update I: I just realized that @array only had three items in it, which is of course why the HoH only has the last item in it. If there's a better way to approach this, I would appreciate comments.
Update II: Thanks very much for all the comments. I believe I have a workable solution now. Thanks very much to all. I will test each method and try to understand each one.

Considered (jbrugger): Delete, as requested by op
Unconsidered (holli): Enough Keep votes (Keep/Edit/Delete: 13/0/2)


In reply to HoH question by cajun

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.