用PERL做个回文的程序,要求忽略大小写,标点符号.
Write a webpage called palindrome.html which will test strings (which may or may not include numbers) to see if they are palindromes. The user can input a string, and then a script will check to see if the string is a palindrome or not, displaying the result to the user on another page (include the original string that they input in the displayed output). You should disregard the case of letters, as well as spaces and any punctuation symbols in the sentence (use Perl string routines to deal with these issues) when you check to see if it is a palindrome.
For example, the string "Madam, I'm Adam" is a palindrome (disregarding upper/lower case, spaces, and punctuation symbols), and the number 15751 is a palindrome too. The strings "Ma'am, I'm Adam" and "34546" aren't.
what's more allow the user to input up to five strings at once and display results for all of them on the same page. If the user only inputs one or two strings to test, then you should only output information about those strings (i.e. don't assume that they will enter exactly five strings).
简单说就是用PERL做个回文的程序,要求忽略大小写,标点符号.
这个是我写的,一直运行不了,大家帮我看看哪里出错了啊!!!!!!!
#!/usr/bin/perl
print "Content-type: text/plain \n\n";
$query_string = $ENV{'QUERY_STRING'};
@array_test=split(/&/, $query_string);
foreach $pair (@array_test){
($key_name, $value) = split(/=/, $pair);
$word =~ tr/+/ /; #remove+into spaces
$word =~ s/%([0-9A-F][0-9A-F])/pack("c",hex($1))/ge;
$word =~ s/\W//g;
$word =~ tr/A-Z/a-z/; # converts $word to upper case.
$word =tr/\,\.\?\:\;\"\'\!//; #deletes all commas and periods from $word
@letters = (split //, $word);
$reverse = (join "", reverse @letters);
if(@letters == 0){
print "No words was inputed\n";
}
elsif(@letters == 1){
print "One letter palindrome.\n";
}
elsif($reverse eq $word){
print "This is a palindrome.\n";
}
else{
print "Not a palindrome.\n";
}