So, I believe this has something to do with the difference between arrays and lists, but I don't understand what's going on here. Can anyone explain how and why Perl treats an expression like (1..4)
differently than (1, 2, 3, 4)
and @{[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