No such thing as a small change | |
PerlMonks |
Re: Truth and Falsehoodby jcb (Parson) |
on Aug 17, 2019 at 22:38 UTC ( [id://11104622]=note: print w/replies, xml ) | Need Help?? |
While I know that you did not label this "[RFC]", this looks like a good draft for a brief tutorial. As currently written, this neglects $#array. I think it would be better to write the first paragraph in "Hash and Array Size" as: To get the number of elements in an array, use scalar, as in scalar @array, or use the array in a scalar context, for example my $size = @array;. To test whether an array is empty or not, simply use it in a boolean context, such as if (@array). To get the largest index in an array, use $#array. To explicitly resize an array, assign a value to $#array. Perl normally grows arrays as needed, but explicitly assigning to $#array can also shrink an array, discarding elements from the high end. I have tried to follow your style in the above text, but I expect that you will further edit that before using it, if you use it. The exists and defined tests also apply to array indexes, in the same way that they apply to hash keys. This can be explained briefly and would go well with adding mention of $#. And one minor stylistic quibble: I think of exceptions as "thrown" with die because they can be "caught" with eval BLOCK, but can warnings be similarly "caught" in Perl or would it be better to say that length returns undef without producing a warning?
In Section
Meditations
|
|