You're nearly there!

It would be worth considering putting your AoH into a hash using the pages as keys. You could then 'lookup' which page you want. You would still have a nice AoH to give HTML::Template.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my (%HoAoH, $page, %H); while (<DATA>){ chomp; if (/^Page/){ (undef, $page) = split /\s+=\s+/; } elsif (/^\[Start]/){ %H = (); } elsif (/^\[End]/){ push @{$HoAoH{$page}}, {%H}; } else{ my ($key, $value) = split /\s+=\s+/; # updated to produce output suitable for HTML::Template #if ($key eq 'varname'){ # $varname = $value; #} #elsif ($key eq 'varval'){ # push @AoH, {$varname => $value}; #} $H{$key} = $value; } } print Dumper(\%HoAoH); my @page2 = $HoAoH{'second page'}; __DATA__ Page = first page [Start] varname = name1 varval = val1 [End] [Start] varname = name2 varval = val2 [End] Page = second page [Start] varname = name11 varval = val11 [End] [Start] varname = name21 varval = val21 [End]
output:
---------- Capture Output ---------- > "C:\Perl\bin\perl.exe" sara.pl $VAR1 = { 'second page' => [ { 'varname' => 'name11', 'varval' => 'val11' }, { 'varname' => 'name21', 'varval' => 'val21' } ], 'first page' => [ { 'varname' => 'name1', 'varval' => 'val1' }, { 'varname' => 'name2', 'varval' => 'val2' } ] }; > Terminated with exit code 0.
As CountZero suggested, something like CGI::Session will help you keep track of which page you need to send.

The idea is that you would store the data in a 'session' on the server. You would also store which page was sent. The next time the script is called you'll know which page is needed. CGI::S will do all this for you!

Have a look at it and let us know how you get on.

Good luck!

Update:
It really is a good idea to use strict and warnings as I have (it will make life a lot easier).
Also notice Data::Dumper. If your dealing with data structures like this your life will be twice as easy!
Update 2:
Added how get page2 to the code
Update 3:
Changed structure to suit HTML::Template


In reply to Re: Parse config file into data strucuture and pass it between pages in CGI script by wfsp
in thread Parse config file into data strucuture and pass it between pages in CGI script by sara2005

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.