Gossamer Forum
Home : General : Perl Programming :

Use of uninitialized value

Quote Reply
Use of uninitialized value
Hello,

I have a problem with a cgi script for ecards. I have the following error message:
Use of uninitialized value at Card.pm line 131.

Here is the part of code where I have the error:
(line 131 is $frag .= "<input type=hidden name=" . $_ ." value=\"" . $this->{in}->{$_} . "\">\n";):

Code:
sub preview
{
my $this = shift;

my $frag;
foreach (@{$this->{params}})
{
$frag .= "<input type=hidden name=" . $_ ." value=\"" . $this->{in}->{$_} . "\">\n";
}
$this->{in}->{frag} = $frag;
$this->write_page('preview.tpl',$this->{in});
}
[/font]
Could you please help me.
Thanks a lot.
Quote Reply
Re: [Lotz] Use of uninitialized value In reply to
Hi Lotz,

Start by assigning a value to $frag:
Code:
my $frag = '';

Also check $this->{in}->{$_} to make sure you have data.

Regards,
Charlie
Quote Reply
Re: [Lotz] Use of uninitialized value In reply to
You could simplify that line by using:

Code:
$frag .= qq|<input type=hidden name="$_" value="$this->{in}->{$_}">\n|;

Does $this->{in} exist before the loop?...if not add:

$this->{in} = {};