http://qs1969.pair.com?node_id=170848

Ovid has asked for the wisdom of the Perl Monks concerning the following question:

In answering a question on the Perl Beginner's list, I stumbled across the following:

#!/usr/bin/perl -w $lines[0] = [ qw/ dog cat bird / ]; print $lines[0][0,1,2];

No, it's not an array slice. The "0,1,2" is a list and each element of the list is evaluated from left to right and the results of the last evaluation (2) are returned. Thus, the above snippet prints "bird", but issues no warnings.

However, if I change the 1 to a 2:

#!/usr/bin/perl -w $lines[0] = [ qw/ dog cat bird / ]; print $lines[0][0,2,2];

I get the following:

Useless use of a constant in void context at C:\test.pl line 3. bird

chromatic guessed that this may be a hack in Perl to allow us to put 1 at the bottom of modules without a warning, but I'm not sure. Is this documented anywhere, or is it a bug?

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.