Like Perl, how to send CGI parameters to the command line?

I usually get data from a web page, but I want to send it from the command line to facilitate debugging.

To get the data, I do something like:

my $query = new CGI; my $username = $query->param("the_username"); 

this does not work:

  $ ./script.pl the_username = user1 

EDIT:

Actually, it works. The if that checked $username was incorrect (using == instead of eq ).

+6
source share
2 answers

As I found out a long time ago, you really can pass query string parameters to a script using CGI.pm. I do not recommend this as the preferred debugging method (it is better to have replicated things stored in files that are then directed to the STDIN script), however it works:

 #!/usr/bin/env perl use warnings; use strict; use CGI; my $cgi = CGI->new; my $param_name = 'the_username'; printf( "The value of '%s' is '%s'.\n", $param_name, $cgi->param($param_name) ); 

Conclusion:

  $ ./t.pl the_username = yadayada
 The value of 'the_username' is 'yadayada'. 
+6
source

CGI reads variables from standard input.

See this part of the CGI.pm documentation:

http://search.cpan.org/dist/CGI/lib/CGI.pod#DEBUGGING

+7
source

Source: https://habr.com/ru/post/897237/


All Articles