需要的最后一块拼图(返回用户请求的值)

时间:2014-11-14 18:55:27

标签: perl xampp cgi

引用一个早先的问题,我已经将我的代码更改为此(我越来越近了)但是它现在读出整个文件而不是我想要的行。 (我想读出一行,其中包含用户在表单上输入的值。

表单代码:

#!\xampp\perl\bin\perl.exe

使用CGI qw /:standard /; #load标准CGI例程    使用CGI :: Carp('fatalsToBrowser');

 print header(); # create the HTTP header
 print  <<HTML

 <head>
  <title>Shop Here</title>
 </head>
 <body>

<h1>list</h1>

 <br />

<form action="doSearch.pl"> 
    animalname:     <input type="text", name="search" size=5><br><br>

 <input type="submit" value="select"> 

 </form> 
 </body>
 </html>

HTML

# <>;


   response form////////////////////////

 use CGI qw(:standard);
 use CGI::Carp('fatalsToBrowser'); 
 $search = new CGI;

 @animallist = param;

 print header, start_html("animal list"); #prints title on tab

$inFile = "animal.txt";
open (IN, $inFile) or
die "Can't find file: $inFile";

 @animallist = (<IN>);
# print @animallist, "\n" ;
foreach $line (@animallist)
{
if ($line =~ $value)
{
  print $line;
  }
  }

      print end_html;

1 个答案:

答案 0 :(得分:0)

你真的应该在你的问题中提出一个问题。

我认为您的代码无效。

我知道如果$ value包含特殊字符,行$line =~ $value很可能无法执行您想要的操作。

看看here(\ Q \ E可能是您想要的)如果这是问题,您需要解决它。