Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

stupid question

Quote Reply
stupid question
 
I'm not sure if this should have been posted to the perl forum, but it's links related so here goes...

Being (very) rusty with perl, can anyone explain to me how to pass a links $rec information to a sub routine along with $in and $dynamic? The last call here works further up the script and everything gets passed through ok. But when trying to pass the $rec information to this sub routine, I'm getting this error message....

Can't use an undefined value as a HASH reference at .../cgi-bin/recommend_it.cgi line 115*.

I know there's a simple answer just waiting to make me look stupid - so fire away.



$rec <-- link information grabbed from database.

if ( $ENV{'REQUEST_METHOD'} eq "POST") { ## If the script has been called from a form, process it.

## PASS THE HASH THE REFERRING PAGE VARIABLE
$rec->{'jumpback'} = $in->param('jumpback'); ## Add jump back info to the link hash.

&process_form ($in, $dynamic, $rec);
}

sub process_form {
# --------------------------------------------------------
my ($in, $dynamic, $rec) = @_;

## Call a sub routine in httmtemplate file, and pass the $rec informaion through to the template again.

&site_html_recommend ({ error => "Sorry an error occurred", %in, %$rec }, $dynamic) and return; #* line 115

}

Quote Reply
Re: stupid question In reply to
You first have to get the record information via get_record in order to pass the record hash (%$rec) to the template file.

Regards,

Eliot Lee

Quote Reply
Re: stupid question In reply to
Yip, the $rec hash has already has been passed the link info prior to this. Thats what the..

$rec <-- link information grabbed from database.

was referring to. Or do you mean I have to get the link information 'again' in the sub routine?

Quote Reply
Re: stupid question In reply to
Are you sure you have the following codes:

Code:

my $rec = $db->get_record ($id, 'HASH');
if ($rec) {
&site_html_recommend ({ error => "Sorry an error occurred", %in, %$rec }, $dynamic) and return;
}
else {
&site_html_error ({error => "Unknown Link", %in}, $dynamic);
}


If not, then the codes won't work...if you grabbing the record in an earlier sub, like sub main...then you have to use the following codes:

Code:

&process_form ({%$rec}, $in, $dynamic);


Regards,

Eliot Lee

Quote Reply
Re: stupid question In reply to
Thanks eliot,

Yip, I've got those codes in place. I'm calling the subroutine 'process_form' from INSIDE the 'sub main', which is where the link ID is getting called and placed into the $rec. All is working well, the $rec contains the link data ok, until I try to pass the $rec details to the process_form sub. This is how it stands at the moment but is still giving a hash error...

inside the sub main I call the sub process_form below...


&process_form ({%$rec}, $in, $dynamic);


which calles this sub routine...


sub process_form {
# --------------------------------------------------------
my ($in, $dynamic, $rec) = @_;

## Call a sub routine in httmtemplate file, and pass the rec informaion through to the template again.

&site_html_recommend ({ error => "Made it to the process_form sub", %in, %$rec }, $dynamic) and return;
}


and is giving the error...

Can't use an undefined value as a HASH reference at... (points to the sub process_form &site_html_recommend call above.)


Can you see anything glaringly obvious stuffed up with the code?