如何从Perl子例程返回标量值

Raj*_*mar -4 perl

我想返回正确的值$message_all,但在给定的场景中它会变回空白.有什么建议?

processing()

print "message_all = $message_all";

sub processing
{
    log ( " Some message");
}

sub log
{
    my $text = shift;
    my $message_all .= $text;
    return "$message_all";
}
Run Code Online (Sandbox Code Playgroud)

Aln*_*tak 7

当然它是空白的 - 你已经$message_alllog()函数内声明了,所以它在它之外是不可用的.

始终在Perl代码中执行此操作:

use strict;
use warnings;
Run Code Online (Sandbox Code Playgroud)

它会告诉你这$message_all是未宣布的.