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.
output:#!/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]
As CountZero suggested, something like CGI::Session will help you keep track of which page you need to send.---------- 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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |