in reply to split line and populate hash shortcut ?
Rather than split, use a regex to extract the key and value and also skip any non-matching lines.
#! perl -slw use strict; use Data::Dumper; my %config; m[^([^#][^=]+)=(.*)$] and $config{ $1 } = $2 while <DATA>; print Dumper \%config; __DATA__ THIS=that name=joe height=heyman #this is a comment age=14
You might want to expand that a little and incorporate warnings about non-matching, non-blank, non-comment lines?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: split line and populate hash shortcut ?
by traveler (Parson) on Feb 14, 2006 at 18:21 UTC | |
|
Re^2: split line and populate hash shortcut ?
by blokhead (Monsignor) on Feb 14, 2006 at 19:39 UTC | |
|
Re^2: split line and populate hash shortcut ?
by leocharre (Priest) on Feb 14, 2006 at 18:10 UTC |