in reply to Recursive Function To Parse File For Generating Hash
I do not recommend this but you can possibly do it very simply. As noted it is already XMLish or even hashish. You can reformat it into a hash quite easily.....
String eval is dangerous but if you own the files and its your box.....
local $/; my $data = <DATA>; # unroll line continuations $data =~ s/\\\n\s+//g; # munge $data =~ s/'/\\'/g; # escape out quote char $data =~ s/}/},/g; $data =~ s/\s*{/' => {/g; $data =~ s/\s*:\s*/' => '/g; $data =~ s/\s*;/',/g; $data =~ s/^(\s*)(?=\w)/$1'/mg; print $data; my $var = eval "{ $data }"; use Data::Dumper; print Dumper $var; __DATA__ library(ABC) { date : 04/10/04; revision : 1.5; conditions () { weather : o'bright ; temperature : 55 C; visible : heavy \ fog; } location(work) : 1; }
There is no doubt that ParseRecDescent could do a better job. But probably not in less lines.
cheers
tachyon
|
|---|