in reply to HoH question

You keep replacing what's in %hash. Don't assign to %hash, assign to elements of %hash. Also, \s+\s+ is the same as \s{2,}.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper::Simple; my %hash; while(<DATA>){ chomp; my @array = split /\s{2,}/; $hash{$array[0]} = { $array[1] => $array[2] }; } print(Dumper(%hash));

Replies are listed 'Best First'.
Re^2: HoH question
by bobf (Monsignor) on Oct 06, 2005 at 06:11 UTC

    Since the values in $array[0] are not necessarily unique, this potentially replaces the contents of $hash{$array[0]}. You need a HoAoH, or some variant thereof.

    Output (note the single entry for 'jennifer', for example):

    $VAR1 = { 'jack' => { 'JHuffman@pulsetech.net' => 'cannot find your ho +stname' }, 'jobs' => { 'kwillis@cors.com' => 'Host not found' }, 'jennifer' => { 'Warranty@onlogixx.com' => 'cannot find your + hostname' }, 'tim' => { 'millionairemaker@freshcornam.com' => 'cannot fin +d your hostname' }, 'susan' => { 'linda@kepro.com.tw' => 'cannot find your hostn +ame' }, 'russ' => { 'orders@koss.com' => 'Host not found' }, 'employment' => { 'LifeShopDirect@freshcornam.com' => 'Host +not found' }, 'clara' => { 'Sandra@camrpc.com' => 'Host not found' } };

Re^2: HoH question
by cajun (Chaplain) on Oct 06, 2005 at 06:12 UTC
    Thanks ikegami. Although your solution is better than mine was, it's still not exactly what I need. The results are as follows. Note jennifer, employment, clara and susan only has one 'entry'.

    %hash = ( 'clara' => { 'Sandra@camrpc.com' => 'Host not found' }, 'jack' => { 'JHuffman@pulsetech.net' => 'cannot find your ho +stname' }, 'tim' => { 'millionairemaker@freshcornam.com' => 'cannot fin +d your hostname' }, 'russ' => { 'orders@koss.com' => 'Host not found' }, 'susan' => { 'linda@kepro.com.tw' => 'cannot find your hostn +ame' }, 'employment' => { 'LifeShopDirect@freshcornam.com' => 'Host +not found' }, 'jobs' => { 'kwillis@cors.com' => 'Host not found' }, 'jennifer' => { 'Warranty@onlogixx.com' => 'cannot find your + hostname' } );
      oops, didn't notice. Change
      $hash{$array[0]} = { $array[1] => $array[2] };
      to
      $hash{$array[0]}{$array[1]} = $array[2];
      which is a shortcut for
      $hash{$array[0]} = {} if not defined $hash{$array[0]}; $hash{$array[0]}{$array[1]} = $array[2];