Why does Perl complain “Use of implicit split to @_ is deprecated”?

前端 未结 3 1278
猫巷女王i
猫巷女王i 2020-12-05 17:49

This code triggers the complaint below:

#!/usr/bin/perl 
use strict;
use warnings;

my $s = \"aaa bbb\";
my $num_of_item = split(/\\s+/, $s) ;
print $num_of_         


        
3条回答
  •  無奈伤痛
    2020-12-05 18:35

    Let diagnostics provide more information:

    use strict;
    use warnings;
    use diagnostics; # comment this out when you are done debugging
    
    my $s = "aaa bbb";
    my $num_of_item = split(/\s+/, $s) ;
    print $num_of_item;
    

    Use of implicit split to @_ is deprecated

    (D deprecated, W syntax) It makes a lot of work for the compiler when you clobber a subroutine's argument list, so it's better if you assign the results of a split() explicitly to an array (or list).

    A better way to get diagnostic info is from the command line:

    perl -Mdiagnostics my_program.pl
    

提交回复
热议问题