Hi Chris,

A few comments on your code - some of which may help you.

On Monday 12 Apr 2010 12:06:16 Chris Coggins wrote:
> I'm having trouble getting a piece of data from a form input to print in
> html. Here's the relevant portion of my code
> 
> sub subroutine {

I hope you didn't call your subroutine "subroutine". It should have a 
descriptive name. Furthermore, next time please include the entire code or 
something that can reproduce it.

> my($hash) = shift;

1. Please add a space after the my so it will be clearer.

2. Generally you should do either of:

{{{
my $hash = shift;
}}}

Or:

{{{
my ($hash, $param2, $param3) = @_;
}}}

And don't call your variable "$hash" as it's not descriptive. (And at the very 
least it's a hash-*reference* not a hash.).

> my($data) = "$hash->{'expl'}";
> 

Again << my $data = $hash->{'expl'}; >> or << my $data = $hash->{expl}; >> 
would be fine. No usual need to stringify it and the (...) will make it be 
evaluated in list context which may cause problems in the future (tough 
probably not here.)

> print "Content-type: text/html\n\n";

You should use << print $cgi->header(); >> or the equivalent for non-CGI.pm 
code. 

> print <<STOPHTML;

You should always say <<"STOPHTML" <<'STOPHTML' <<`STOPHTML` etc. with 
explicit quotes depending on what you say. Otherwise, you may not be sure that 
it's doing the right thing (nor will your readers). See Perl Best Practices 
for more information.

> <div class="empdata">This employee has $data</div>
> STOPHTML
> }
> 
> The result is This employee has
> 

Seems like $data is empty for some reason. You can try debugging the script 
locally using perl -d and see where you've gone wrong.

Regards,

        Shlomi Fish

> When I try to print from a separate line like so,
> print <<STOPHTML;
> <div class="empdata">This employee has
> STOPHTML
> print "$data";
> }
> 
> I either get a 500 error or the $data string is not there as in the
> first instance of code. Can someone help?

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Best Introductory Programming Language - http://shlom.in/intro-lang

Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to