in reply to Re^2: Modelling a data structure
in thread Modelling a data structure

Plan B was going to be to go with an XML config file...

You mean something like this?

$ cat test.xml <?xml version="1.0"?> <filelist> <file name="file1"> <field name="field1" start="50" length="20"/> <field name="field2" start="80" length="20"/> <field name="field3" start="100" length="20"/> </file> <file name="file2"> <field name="field1" start="52" length="22"/> <field name="field2" start="82" length="22"/> <field name="field3" start="120" length="22"/> </file> <file name="file3"> <field name="field1" start="53" length="23"/> <field name="field2" start="83" length="23"/> <field name="field3" start="130" length="23"/> </file> </filelist> $ perl -MXML::Simple -MData::Dumper -e '$x=XMLin("test.xml"); print Du +mper($x)' $VAR1 = { 'file' => { 'file2' => { 'field' => { 'field1' => { 'length' => '22' +, 'start' => '52' }, 'field2' => { 'length' => '22' +, 'start' => '82' }, 'field3' => { 'length' => '22' +, 'start' => '120' } } }, 'file1' => { 'field' => { 'field1' => { 'length' => '20' +, 'start' => '50' }, 'field2' => { 'length' => '20' +, 'start' => '80' }, 'field3' => { 'length' => '20' +, 'start' => '100' } } }, 'file3' => { 'field' => { 'field1' => { 'length' => '23' +, 'start' => '53' }, 'field2' => { 'length' => '23' +, 'start' => '83' }, 'field3' => { 'length' => '23' +, 'start' => '130' } } } } };
But... what? Looks pretty simple to me. I'd rather not have all those data values hard-coded in the perl script itself, and reading them from a basic xml file seems like a no-brainer.

I guess it's a little goofy that there are two layers in XML::Simple's "default" hash structure that are sort of useless ("file" and "field"), but if you tried a different way of structuring the xml (and/or spent some time with the XML::Simple man page), you could probably improve on that. (Or you could just use the default as-is and get done quicker.)