in reply to Probably an easy map question
You could forget the chomp and split and do it with a regexp.
use Data::Dumper; my %h = map { /^([^=]+?)\s*=\s*(\S.*)/ } <DATA>; print Dumper \%h; __DATA__ a = fred b = 1 ignorethis c = ===
Output:
$VAR1 = { 'c' => '===', 'a' => 'fred', 'b' => '1' };
This works because the regexp evaluates to a list of the contents of the two captures. What's nice about this is that it elegantly handles values that have an equal sign in them. It also just plain skips over any line that doesn't fit the format.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Probably an easy map question
by pobocks (Chaplain) on Jan 15, 2009 at 04:49 UTC | |
by kyle (Abbot) on Jan 15, 2009 at 04:53 UTC | |
by pobocks (Chaplain) on Jan 15, 2009 at 04:57 UTC |