【发布时间】:2013-07-09 20:46:32
【问题描述】:
我正在尝试编写一个允许编辑单独的问题和答案文件的 perl 脚本。如果不编写看起来很荒谬、效率低下的代码,我似乎无法找出似乎可以正常工作的东西。
我希望它能够向文件添加全新的问题/答案,以及编辑现有的问题/答案。关于如何完成这项工作的任何建议?
编辑:假设我有一个 textarea。我可以制作一个按钮,从相关文件中删除在 textarea 中输入的文本吗?一个文本区域,当您输入问题时,您可以选择按“删除”按钮,如果 .txt 文件中存在该问题,请将其从文件中删除?
这是脚本:
if($newquestion != $oldquestion and $newanswer != $oldanswer) {
print $ANS "$newquestion\t$newanswer\n";
} else {
if($newquestion != $oldquestion and $newanswer == $oldanswer) {
print $ANS "$newquestion\t$newanswer\n";
} elsif($newquestion == $oldquestion and $newanswer != $oldanswer) {
print $ANS "$oldquestion\t$newquestion\n";
}
}
}
这是html:
<html>
<body>
Edit Questions and Answers!<br><br>
Type the question in the first area, and the answer to it in the other<br>
~answerlist~<br><br>
<form action="viewquestions.dhtml" method="post">
Questions and Answers:<br>
<textarea rows="1" cols="25" name="newquestion">Question
</textarea>
<textarea rows="1" cols="25" name="newanswer">Answer
</textarea>
<input type="submit" value="submit"/>
<input type="hidden" name="site" value="~site~"/>
<input type="hidden" name="xs" value="~xs~"/>
<input type="hidden" name="username" value="~username~"/>
</form>
<a href="/client_homepage.dhtml~useridtext~&frompage=View and Answer Questions">Return to home page</a><br>
</body>
</html>
【问题讨论】:
-
您是否有现有的 HTML 文件,如果它是一个新问题,您可以添加或创建这些文件,并在需要时提供整个内容?有点像stackoverflow?您可能需要考虑将文件保存在 XML 中,因为有许多用于处理 XML 的包。然后,您可以使用 XSLT 包将其转换为 HTML。
-
如果你在比较字符串,你必须使用
eq和ne。==和!=用于比较数字。