I'm having a little trouble following the documentation on pushing. It gives us the example:Well first, you should understand the syntax of this kind of generic example first. It is pretty common, throughout the docs, that symbolic representations are represented in upper case. For example, in a regexpI'm assuming (LIST) should be an array list, and if that's so it would have been nice if they said that in the docs because at first I thought it was a filehandle of some kind.for $value (LIST) { $ARRAY[++$#ARRAY] = $value; }
"PATTERN" doesn't really represent the upper case word "PATTERN", but any generic regexp pattern. It's something like a variable, for a code template./PATTERN/
In the same way, in the code you brought along, "LIST" is any list. It can be @abc or $a, $b, $c or $a, @b, $c or... Anything, really.
$ARRAY[..] = $value looks like a hash rather than an array so what's really happening?You must be thinking of PHP. In Perl, hashes are never used in combination with square brackets. So this is a real array, with numerical indexes.
Anyway, "@ARRAY", again, represents any kind of array, for example @{$arrayref}. $#ARRAY is the associated "last index" value of this array. I didn't even know you could use it as an Lvalue, for increment. But, why not. Anyway, what this snippet represents is: increment the size of the array by one, and store the value of $value as the new last array item.
HTH.
In reply to Re: array pushing
by bart
in thread array pushing
by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |