As you say you are learning Perl, it may be helpful for you to use diagnostics; in addition to enabling strictures and warnings (which, IMO, should always be done). Another good question to ask in a situation like this is "Why is 6 the only thing printed?". (Some of the diagnostic output in the example below has been elided, and sorry about all the line wrap.)
>perl -le "use warnings; use strict; use diagnostics; my $list = (2,3,4,5,6); print qq{$list \n}; " Useless use of a constant in void context at -e line 1 (#1) (W void) You did something without a side effect in a context that + does nothing with the return value, such as a statement that doesn't re +turn a value from a block, or the left side of a scalar comma operator. + ... Another common error is to use ordinary parentheses to construct a + list reference when you should be using square or curly brackets, for example, if you say $array = (1,2); when you should have said $array = [1,2]; The square brackets explicitly turn a list value into a scalar val +ue, while parentheses do not. So when a parenthesized list is evaluat +ed in a scalar context, the comma is treated like C's comma operator, wh +ich throws away the left argument, which is not what you want. See perlref for more on this. ... 6
In reply to Re: Perl Lists and Arrays
by AnomalousMonk
in thread Perl Lists and Arrays
by sarathi.mh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |