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)