in reply to Selective String extraction & formatting
use strict; use warnings; use Data::Dumper; my %h; while (<DATA>) { while (m/(\w+)\s?:\s?(\S*)/g){ $h{$1} = $2; } } print Dumper \%h; __DATA__ firstName : firstValue Name2: Value2 Name3:Value3 Name4:value4 Name5: Name6:
Note that use of \w and \S is guesswork on my part - it works for the example you gave, but it depends on your data format if that's the right choice.
Please only use <code>...</code> tags for code, put your question into normal paragraphs. See Writeup Formatting Tips.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Selective String extraction & formatting
by harishnuti (Beadle) on Jul 03, 2008 at 09:17 UTC | |
by ww (Archbishop) on Jul 03, 2008 at 12:17 UTC | |
by harishnuti (Beadle) on Jul 09, 2008 at 13:47 UTC |