O.K., I FINALLY got all of the data I wanted into an array of arrays of arrays(etc). Now, I need to parse the thing. Since the first couple of arrays inside are merely references to the next, I decided to use a recursive sub to put everything into the hash. Here is the code:
#!/opt/perl5/bin/perl -w use strict; use Parse::RecDescent; use Data::Dumper; use vars qw($grammar); BEGIN{ $::RD_AUTOACTION = q{ [@item[1..$#item]] }; } $grammar = q( file: section(s) section: header pair(s?) header: /\[(\w+)\]/ { $1 } pair: /(\w+)\s?=\s?(\w+)(\s+[\#\;][\w\s]+)?\n/ { if(!defined $3){ [$1,$2]; }else{ [$1,$2,$3]; } } ); my $parser= Parse::RecDescent->new($grammar); my $text; { $/=undef; $text=<DATA>; } my $tree=$parser->file($text); my ($key,$x,%Config); my $config=deparse($tree); print Dumper($config); sub deparse{ my $aoa=shift; for $x (0..$#{$aoa}){ if(ref($aoa->[$x])){ $key=deparse($aoa->[$x]); }else{ if(scalar(@$aoa) == 2){ chomp $aoa->[0]; $y=$aoa->[0]; $Config{$y}=undef; return $key; }elsif(scalar(@$aoa) == 3){ if(defined $aoa->[2]){ $aoa->[2]=~s/^\s+[\;\#]//; chomp $aoa->[2]; $Config{$key}{$aoa->[0]}=[$aoa->[1],$aoa->[2]]; return; }else{ $Config{$key}{$aoa->[0]}=$aoa->[1]; return; } } } } my $return=\%Config; return $return; } __DATA__ [Section1] key1=value1 key2=value2 #Comment2 key3=value3 [Section2] key4=value4 key5=value5 key6=value6 ;Comment 6
It prints out the section headers, but each one of those is undef. Where exactly am I going wrong in the sub?

TStanley
--------

In reply to How do I set up the recursion? by TStanley

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.