Perl 5从用户那里获得输入,并从数据库中删除。

时间:2022-09-06 16:32:40

I have a simple Perl script, I simply want to get the input from the user terminal style and use that to delete a row within the table in the database, here is the code snippet:

我有一个简单的Perl脚本,我只想从用户终端样式中获取输入并使用它来删除数据库中表中的一行,以下是代码片段:

# something not right here..
my $name = <STDIN>;

my $sth3 = $dbh->prepare("DELETE FROM animals WHERE animal_name = ?");

$sth3->bind_param(1, $name);

$sth3->execute() or die 'nope...';
print $sth3->rows;
$sth3->finish();

The connection is working, however, the query will not pick up the value to delete so 0 rows are always returned. Any help would be nice with this, I believe I am going about this the right way but making a small mistake in binding this to the query. Thank you in advance.

但是,该连接正在工作,查询将不会获取要删除的值,因此总是返回0行。任何帮助都是好的,我相信我的方法是正确的,但是在将它绑定到查询时犯了一个小错误。提前谢谢你。

1 个解决方案

#1


2  

You need to chomp the input. Do

你需要咀嚼输入。做

my $name = <STDIN>;
chomp($name);

or

chomp(my $name = <STDIN>);

#1


2  

You need to chomp the input. Do

你需要咀嚼输入。做

my $name = <STDIN>;
chomp($name);

or

chomp(my $name = <STDIN>);