in reply to Please help with Hash Key,value issue
use strict; use warnings; use Data::Dumper; my %data; while (<DATA>) { my ($k, $v) = split; push @{ $data{$k} }, $v; } print Dumper(\%data); __DATA__ k1 5 k2 3 k1 7
Prints out:
$VAR1 = { 'k2' => [ '3' ], 'k1' => [ '5', '7' ] };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Please help with Hash Key,value issue
by mmittiga17 (Scribe) on Mar 11, 2009 at 18:52 UTC | |
by bellaire (Hermit) on Mar 11, 2009 at 20:40 UTC |