This is an SDL function which takes a binding and returns a string which is perl code to re-create an alternate implementaiton of the binidng as a perl hash.
Has anyone done this before? I personally need it to extract "a subset" of the build_bmp import tree. I want to use SDL to parse the .ves file to avoid any parsing mistakes or limitations, but i need the data in a perl script outside, so i wrote this.
I have to handle lists, bools, all the types, but you'll get the idea.
/**nocache**/ binding2perlhash_recursion (b, prefix) { str = ""; foreach [n = v] in b do { this_prefix = prefix + "{" + n + "}"; str += if _is_binding(v) then binding2perlhash_recursion(v, this_prefix) else (this_prefix + " = \"" + (if _is_int(v) then ./itoa(v) else v) + "\";\n"); }; return str; }; /**nocache**/ binding2perlhash (b, hash_ref_name = "href") { return binding2perlhash_recursion (b, "$$" + hash_ref_name); };
example test.ves:
{ return [vbk.dat.ves.pl = binding2perlhash([first = 1, second = "two", nested = [three = 333, four = "fore"]], "myhashr")]; }
run via:
vesta -shipto ~/mydir/ /path/test.ves
returns a file that looks like this:
$$myhashr{first} = "1"; $$myhashr{second} = "two"; $$myhashr{nested}{three} = "333"; $$myhashr{nested}{four} = "fore";
This perl script can consume it:
use Data::Dumper; # eval the generated .pl file do "/home/user/mydir/vbk.dat.ves.pl"; # use Data::Dumper to print the resulting hash ref print Data::Dumper->Dump([$myhashr],[qw($myhashr)]);