Why does Perl complain that it "cannot change the call to a non-lvalue subroutine"?

I have index.pl and subs.pl. When I run the program, the user inserts the date of birth, and then is passed to the subprogram getage()in subs.pl, which has many subprograms. getage()than implicitly calls another routine called validate()that checks the date entered by the user.

When I run index.pl and the user enters a date like 03-04-2005, the following error appears:

cannot change the call of the non-lvalue subroutine in the line subs.pl 85, <> line 1

On the 85th line of subs.pl, I have:

list(my $val,my @value) = validate($dob);

validate()returns a message and date($dob)that is sent from getage().

Some code from validate ():

sub validate {
    my $dob = shift;
    my $error;
    my @test;
    @test = split("-",$dob);
    if (!@test) {
        $error = "date separator should be - ";
        return ($error,@test);
    }
    ...
+3
3

:

my ($val, @value) = validate($dob);

, , , - ( validate(), list()?)

list() $val @value , : ($val, @value),

+4

lvalue - , . (, , ). , , , .

: validate($dob) list($val, @value).

+1

list(my $val,my @value) = validate($dob);

delete the "list" and it works great

t

(my $val,my @value) = validate($dob);

thanks to Kayra and the others who answered

0
source

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


All Articles