Why does Perl autovivify in this case?

前端 未结 4 1291
清酒与你
清酒与你 2020-12-10 19:45

Why does $a become an arrayref? I\'m not pushing anything to it.

perl -MData::Dumper -e \'use strict; 1 for @$a; print Dumper $a\'
$VAR1 = [];
<         


        
4条回答
  •  眼角桃花
    2020-12-10 20:39

    $a and $b are special variables in Perl (used in sort) and have a special scope of their own.

    perl -MData::Dumper -e 'use strict; 1 for @$c; print Dumper $c'
    

    produces

    Global symbol "$c" requires explicit package name at -e line 1.
    Global symbol "$c" requires explicit package name at -e line 1.
    Execution of -e aborted due to compilation errors.
    

提交回复
热议问题