in reply to Using Split to load a hash
Update: Added ",$_,2" to the split, to handle addresses with a comma, and modified test cases acordinglymy $txt=<<'TEXT_END'; nameone, addr1 info (without commas in it) nametwo, address two, city (with a comma) namethree, address three fields TEXT_END my %info; my ($name,$addr); for (split "\n",$txt) { ($name,$addr) = split ',',$_,2; $info{$name} = $addr; } my ($key,$val); while (($key,$val)= each(%info)) { print "$key->$val\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using Split to load a hash
by izut (Chaplain) on Aug 19, 2006 at 17:59 UTC |