Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Does Perl have if(isset?

by beanscake (Initiate)
on Jan 24, 2014 at 20:13 UTC ( #1071990=perlquestion: print w/ replies, xml ) Need Help??
beanscake has asked for the wisdom of the Perl Monks concerning the following question:

Please i need a solution for this, i want to use (PERL) to process a form instead of PHP, now my only problem is converting this LINE to (PERL) SCRIPT.
<?php if(isset($_POST['comment'])) $comment = $_POST['comment']; ?>
Thank you.

Comment on Does Perl have if(isset?
Download Code
Re: Does Perl have if(isset?
by Your Mother (Canon) on Jan 24, 2014 at 20:21 UTC

    You should put your code in <code> tags. And without knowing a little Perl this is unlikely to get you far but this is roughly equivalent. I didn't use the if block because it is unperly (to me) when there is no real else.

    use strict; # DO NOT LEAVE OUT. use warnings; # What did I just say?! use CGI ":standard"; my $comment; $comment = param("comment") if request_method() eq "POST"; # Note, $comment could be undefined/uninitialized here # but this is similar to your logical block.
Re: Does Perl have if(isset?
by Corion (Pope) on Jan 24, 2014 at 20:29 UTC

    According to the PHP documentation on isset(), the function returns true if the variable has a defined value. This would be equivalent to the defined function of Perl:

    $comment= param('comment') if defined param('comment');

    I think the $_POST hash in PHP is populated by HTTP POST parameters - you would have to check that too.

Re: Does Perl have if(isset?
by karlgoethebier (Curate) on Jan 24, 2014 at 21:01 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1071990]
Approved by Corion
Front-paged by Sinistral
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-11-27 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (183 votes), past polls