cajun has asked for the wisdom of the Perl Monks concerning the following question:
When executed, only the last item 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
Thanks,%hash = ( 'employment' => { 'LifeShopDirect@freshcornam.com' => 'Host +not found' } );
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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HoH question
by ikegami (Patriarch) on Oct 06, 2005 at 05:56 UTC | |
by bobf (Monsignor) on Oct 06, 2005 at 06:11 UTC | |
by cajun (Chaplain) on Oct 06, 2005 at 06:12 UTC | |
by ikegami (Patriarch) on Oct 06, 2005 at 06:27 UTC | |
|
Re: HoH question
by bobf (Monsignor) on Oct 06, 2005 at 06:04 UTC | |
|
Re: HoH question
by McDarren (Abbot) on Oct 06, 2005 at 05:50 UTC | |
|
Re: HoH question
by tphyahoo (Vicar) on Oct 06, 2005 at 10:36 UTC |