Why is this Perl code using 1; expression?

Possible duplicate:
Why you need to put 1; at the end of the Perl 5 module?

From this page Perl :: Critic :: Policy :: Subroutines :: RequireFinalReturn , this is sample code

package Password;
# every time the user guesses the password wrong, its value
# is rotated by one character
my $password;
sub set_password {
    $password = shift;
}
sub check_password {
    my $guess = shift;
    if ($guess eq $password) {
        unlock_secrets();
    } else {
        $password = (substr $password, 1).(substr $password, 0, 1);
    }
}
1;
  • Why used 1;at the end? What does this statement mean for the compiler?

I tried the code with and without it, the result looks the same.

+3
source share
2 answers

, Perl "", . true, , , die. , , , , .

1; - , , .

, , .

+7

perldoc -f require:

true , 1; , return true . 1;, .

1; , use script, :

Password.pm did not return a true value
BEGIN failed--compilation aborted
+4

Source: https://habr.com/ru/post/1765505/


All Articles