in reply to Re^2: question:File to hash using map
in thread question:File to hash using map
Zaxo's solution actually does work. I think you've made a mistake in the way you pass the data to Data::Dumper.
You need to pass a reference to the hash, not just the hash itself.
Try this:
use strict; use warnings; use Data::Dumper; # Pretend that I've already read the file into @lines ... my @lines = ( 'A, B, C', 'D,E,F', 'G, H,I', ); # Zaxo's solution my %hash = map { chomp; split ',', $_, 2 } @lines; # View the data (use a *reference* to the hash, though!) printf "Data => %s\n", Dumper(\%hash);
which correctly outputs the following...
Data => $VAR1 = { 'A' => ' B, C', 'D' => 'E,F', 'G' => ' H,I' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: question:File to hash using map
by narashima (Beadle) on Jan 30, 2007 at 17:19 UTC |