Hi Chris, I'm not sure exactly your end goal, or whether the $VAR1 data from the Dumper output you show is valuable to you at all. But if not you might consider using one of the config file parsers from CPAN. It might take some coercing to get one to conform to your needs, but you seem to have the flexibility to change the format of your files; an automated translation should be doable. Plus you'll get the escaping and quoting features, that you mention are lacking in your code.

Here's a quick example

use strict; use warnings; use Data::Dumper; use Config::Scoped; my $cs = Config::Scoped->new(); my @lines = ("data{all = [\n", <DATA>, "]}\n"); my $Config = $cs->parse(text => join('', @lines))->{data}->{all}; print Dumper($Config); __DATA__ { name = john location = uk interests = [ programming cycling ] } # An ignored comment { name = laura interests = [ knitting tennis dancing ] } { location = canada interests = [[ dogs horses ] cars] }

Which displays:

$VAR1 = [ { 'interests' => [ 'programming', 'cycling' ], 'location' => 'uk', 'name' => 'john' }, { 'interests' => [ 'knitting', 'tennis', 'dancing' ], 'name' => 'laura' }, { 'location' => 'canada', 'interests' => [ [ 'dogs', 'horses' ], 'cars' ] } ];

If you absolutely need the keys that have undefined values as in your example output, the code can be changed to include them. It should be as easy to write a translator from your existing files into this format, as for the new syntax you are proposing. However, other CPAN options might be more to your liking.


In reply to Re: Dive data with automatic array indexing by Loops
in thread Dive data with automatic array indexing by peterp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.