in reply to How to analyse structured data to get a hash
If you dont do your own homework you wont learn anything.my %datahash; while (my $line=<DATA>) { chomp $line; $line=~s/^\s+//; $line=~s/\s+$//; my ($var,$val0)=split('=',$line,2); $val0='' unless (defined $val0); if ($val0=~m/^\"(.*)\"$/) { $datahash{$var}=$1;} else {$datahash{$var}=$val0;} } use Data::Dumper; print Dumper({datahash=>\%datahash}); __DATA__ Attr num="101" name="Created" desc="Time file was created." type="t" ord="3" value="2017-06-03T11:27:23+01:00" noeq noval= noquotes=noquotes
Result
$VAR1 = { 'datahash' => { 'name' => 'Created', 'Attr num' => '101', 'noeq' => '', 'noquotes' => 'noquotes', 'ord' => '3', 'noval' => '', 'value' => '2017-06-03T11:27:23+01:00', 'desc' => 'Time file was created.', 'type' => 't' } };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to analyse structured data to get a hash
by Marshall (Canon) on Jun 04, 2017 at 03:55 UTC |