0

How we can fetch data sent via POST request in Perl? Is it similar and easy as in PHP, for instance $_POST["name"])? If someone could point me to the websites which will help me to solve this, I will be thankful.

I found this but I cannot find nothing like 'receive/fetch HTTP POST data', just 'Posting Form Data', which is not what I need now.

  • Possible duplicate of [how to get POST values in perl](http://stackoverflow.com/questions/11088538/how-to-get-post-values-in-perl) – Matt Jacob Jan 26 '16 at 18:51

1 Answers1

2

So you're writing Perl scripts for a web server? And you want to know a quick way to get data from the request?

use CGI;

This was such a core Perl standard 20 years ago. Whole sites consisted of just Perl-CGI scripts.

my $q = CGI->new();
if ( $q->param()) { 
    my $name_value = $q->param( 'name' );
}

More here, here and here.

You can probably look at Template and there are more up-to-date web application platforms. But, if you just want post parameters from a form, use CGI;

Axeman
  • 29,660
  • 2
  • 47
  • 102
  • I am beginner in Perl/CGI, so thanks for these links and explanations, I'll read them all. –  Jan 26 '16 at 14:40
  • @Lazar, are you using Apache? If you are, then you might think about [mod_perl](https://perl.apache.org/docs/tutorials/), which makes web apps more "appy". My last perl job, was a Apache-mod_perl/CGI/Template stack. – Axeman Jan 26 '16 at 14:43
  • Yes I am using Apache. –  Jan 26 '16 at 14:45
  • 1
    @Lazar: Just for info,You don't have to take care of GET/POST, the sames methods apply for both. – Toto Jan 26 '16 at 14:46
  • @Toto, I was thinking about mentioning that, but I thought the tutorial would probably fill that in. – Axeman Jan 26 '16 at 14:48