所以,我相信这与数组和列表之间的区别有关,但我不明白这里发生了什么。谁能解释一下 Perl 如何以及为什么将表达式 like与and(1..4)
区别对待?(1, 2, 3, 4)
@{[1..4]}
$ perl -de1
Loading DB routines from perl5db.pl version 1.31
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(-e:1): 1
DB<1> x scalar (1,2,3,4)
0 4
DB<2> x scalar (1..2,3,4)
0 4
DB<3> x scalar (1,2..3,4)
0 4
DB<4> x scalar (1,2,3..4)
0 ''
DB<5> sub foo { (1..4) } # (the actual problem case, except 4 would be a variable)
DB<6> x scalar foo()
0 ''
DB<7> sub bar { @{[1..4]} } # (the workaround)
DB<8> x scalar bar()
0 4