in reply to Parsing semi-erratic text
The data you submitted *does* have newlines.
while (<DATA>) { my ($key, $val) = /^\s*([^:]*?)\s*:\s*(.*?)\s*$/ or next; print("[$key:$val]\n"); }
and
while (<DATA>) { my ($key, $val) = split(/:/, $_, 2); next if not defined $val; s/^\s+//, s/\s+$// for $key, $val; print("[$key:$val]\n"); }
both do the trick.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Parsing semi-erratic text
by SamCG (Hermit) on Aug 23, 2006 at 19:50 UTC | |
by ikegami (Patriarch) on Aug 23, 2006 at 20:04 UTC |
In Section
Seekers of Perl Wisdom