R
Rui Maciel
I want to pass a hash to a sub through as a sub parameter. In order to do so I've written the
following sub:
<code>
sub print_http(;%)
{
if(@_ != 0)
{
my (%params) = $_[0]; # line 15
print "Content-Type: ";
exists $params{"type"} ? print $params{"type"}: print "text/html"; #line 17
print "; ";
exists $params{"charset"} ? print $params{"charset"}: print "charset=ISO-8859-1";
}
else
{
print "Content-Type: text/html; charset=ISO-8859-1";
}
print "\n\n";
}
</code>
Yet, it throws the following error messages:
test.pl: Odd number of elements in hash assignment at ./index.pl line 15.
test.pl: Use of uninitialized value $params{"type"} in print at ./index.pl line 17.
What am I doing wrong? And what's the best way to pass a hash to a sub?
Thanks in advance,
Rui Maciel
following sub:
<code>
sub print_http(;%)
{
if(@_ != 0)
{
my (%params) = $_[0]; # line 15
print "Content-Type: ";
exists $params{"type"} ? print $params{"type"}: print "text/html"; #line 17
print "; ";
exists $params{"charset"} ? print $params{"charset"}: print "charset=ISO-8859-1";
}
else
{
print "Content-Type: text/html; charset=ISO-8859-1";
}
print "\n\n";
}
</code>
Yet, it throws the following error messages:
test.pl: Odd number of elements in hash assignment at ./index.pl line 15.
test.pl: Use of uninitialized value $params{"type"} in print at ./index.pl line 17.
What am I doing wrong? And what's the best way to pass a hash to a sub?
Thanks in advance,
Rui Maciel