Search code examples
perlcpan

How do I fix the undefined subroutine main error


I am using the CPAN Unix::Passwd::File module, and when a I use any of its functions, the script throws the error: Undefined subroutine &main

For example, for get the max uid:

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

my $res = get_max_uid();

the error is Undefined subroutine &main::get_max_uid called at scriptname.pl line 4


Solution

  • A quote from the docs:

    This function is not exported by default, but exportable.

    Try:

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

    or:

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