如何修复未定义的子例程主要错误

How do I fix the undefined subroutine main error

我正在使用 CPAN Unix::Passwd::File 模块,当我使用它的任何功能时,脚本会抛出错误:Undefined subroutine &main

例如获取最大uid:

#!/urs/bin/perl
use Unix::Passwd:File;

my $res = get_max_uid();

错误是Undefined subroutine &main::get_max_uid called at scriptname.pl line 4

引自文档:

This function is not exported by default, but exportable.

尝试:

my $res = Unix::Passwd:File::get_max_uid();

或:

use Unix::Passwd:File qw(get_max_uid);