我正在编写 Perl 代码并DBI
在文件中使用扩展名为.pm
.
导入DBI
模块时,出现如下错误
syntax error at /etc/perl/Foo.pm line 13, near "DBI:"
Compilation failed in require at join.pl
在join.pl
文件中,我们将模块Foo.pm
称为
use Foo;
Foo::dbconnect();
里面的代码Foo.pm
是这样的
#!/usr/bin/perl
package Foo;
use DBI;
sub dbconnect {
my $database = "DB_NAME";
my $user ="user_name";
my $password = "password";
my $dsn = "dbi:mysql:$database:localhost:3306";
my $connect = DBI:connect->($dsn, $user, $password)
or die "can't connect to the db $DBI::errstr\n";
return $connect;
}
1;
我在行中收到错误
my $connect = DBI:connect->($dsn, $user, $password)
or die "can't connect to the db $DBI::errstr\n";
请帮我解决这个问题。