简体   繁体   中英

PERL/CGI- gets more than text from input textarea

I'm not at all familiar with perl, but have some understanding of html. I'm currently trying to configure code from an online program that processes text inputted from the user to calculate and output a few important numbers in order to do the same for a large number of files containing text in a local directory. The problem lies in my lack of understanding for how or why the code from the site is splitting the inputted text by looking for & and =, as the inputted text never contains these characters, and neither my files. Here's some of the code from the online program:

if ($ENV{'REQUEST_METHOD'} ne "POST") { 
    &error('Error','Use Standard Input by METHOD=POST'); 
}

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

if ($buffer eq '') { 
    &error('Error','Can not execute directly','Check the usage'); 
}

$ref = $ENV{'HTTP_REFERER'};

@pairs = split(/&/,$buffer);

foreach $pair (@pairs) {
    ($name,$value) = split(/=/,$pair);
    if ($name eq "ATOMS") { $atoms = $value; }

It then uses these "pairs" to appropriately calculate the required numbers. The input from the user is simply a textarea named "ATOMS", and the form action is the cgi script:

<form method=POST action="/path/to/the/cgi/file.cgi">
<textarea name="ATOMS" rows=20 cols=80></textarea>
</form>

I've left out the less important details of both the html and perl codes. So far all I've been able to do is get all the content from all files in a given directory in a text format, but when I input this into the script that uses the text from textarea to calculate the values (in place of the variable $buffer), it doesn't work, which I suspect is due to the split codes, which cannot find the & and = symbols. How does the code get these symbols from the online script, and how can I implement that to use for my local files? Let me know if any additional information is needed, and thanks in advance!

The encoding scheme forms use (by default) to POST data over HTTP consists of key=value pairs (hence the = ) which are separated by & characters.

The latter doesn't much matter for your form since it has only one control in it.

This is described pretty succinctly in the HTML 4 specification and in more detail in the HTML 5 specification .

If you aren't dealing with data from a form, you should remove all the form decoding code.

Not sure where you got that code from, but it's prehistoric (from the last millennium).

You should be able to replace it all with.

use CGI ':cgi';

my $atoms = param('ATOMS');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM