Hello all,
I'm fairly new to cgi scripting, html templates and perl. I am trying to sort an array of hash (which represents rows of a table) and having trouble with passing the data from html to cgi script (so I can sort). I know how to pass the array to the template but not vice versa.
Essentially the flow goes like this (a snippet and simplified):
1. Input a value, query the database, output a table (this is where I get stuck)
2. Problem: click on a sort submit button, which in turns triggers a cgi script...I am able to pass single variables to the triggered cgi script but I am stuck in passing the data(an array of hash values) that I want sorted to that cgi script. (POST if you want to know.)
In the beginning:
The query cgi declares array of hash like this:
pseudocode (i'mlazy so sue me )
First, query my database
while we fetch rows from the successful sql query
fill the hash
$row{myvalue} = $data_row[0]; #and so on
push the hash onto @rows
}
#set my template parm
$template->param(ROWS=>\@row);
THEN I display it then which is fine but then..say I want to pass @rows to another cgi script w/o having to requery the database again....this is where I'm mystified.
I've tried the following:
1. created a form where sort.cgi is called and I pass 2 values (that goes thru ok) but the array of hash (the stuff I need to sort!) doesn't.
I keep getting compiling errors (attempt to set parameter x with an array ref - parameter is not a TMPL_LOOP. and what was that I'm wondering...lol.
My cgi script that receives it from the template that displays the table:
my $q=new CGI;
my @data = $q->param('ROWS');
I want to sort the array then output it in a new sorted list (my intent is honorable I assure you. ) I've been trying to find this answer for so long..that I'm delirious..lol.
So, in short, I'mlooking for a syntax or example how to set or access an array of hash from template to cgi script (not from script to template)..if anyone could help, I'd appreciate it.
Thank you much,
Tarianna - a very sleepy programmer
I'm fairly new to cgi scripting, html templates and perl. I am trying to sort an array of hash (which represents rows of a table) and having trouble with passing the data from html to cgi script (so I can sort). I know how to pass the array to the template but not vice versa.
Essentially the flow goes like this (a snippet and simplified):
1. Input a value, query the database, output a table (this is where I get stuck)
2. Problem: click on a sort submit button, which in turns triggers a cgi script...I am able to pass single variables to the triggered cgi script but I am stuck in passing the data(an array of hash values) that I want sorted to that cgi script. (POST if you want to know.)
In the beginning:
The query cgi declares array of hash like this:
pseudocode (i'mlazy so sue me )
First, query my database
while we fetch rows from the successful sql query
fill the hash
$row{myvalue} = $data_row[0]; #and so on
push the hash onto @rows
}
#set my template parm
$template->param(ROWS=>\@row);
THEN I display it then which is fine but then..say I want to pass @rows to another cgi script w/o having to requery the database again....this is where I'm mystified.
I've tried the following:
1. created a form where sort.cgi is called and I pass 2 values (that goes thru ok) but the array of hash (the stuff I need to sort!) doesn't.
I keep getting compiling errors (attempt to set parameter x with an array ref - parameter is not a TMPL_LOOP. and what was that I'm wondering...lol.
My cgi script that receives it from the template that displays the table:
my $q=new CGI;
my @data = $q->param('ROWS');
I want to sort the array then output it in a new sorted list (my intent is honorable I assure you. ) I've been trying to find this answer for so long..that I'm delirious..lol.
So, in short, I'mlooking for a syntax or example how to set or access an array of hash from template to cgi script (not from script to template)..if anyone could help, I'd appreciate it.
Thank you much,
Tarianna - a very sleepy programmer