Why? < provides scalar context to its operands. | [reply] |
Thanks for that and am not aware of such a context reasoning
One more question
for (my $i = 0; $i < @molecules; $i ++) {
Instead of the above
my $num_elements = scalar(@molecules);
for (my $i = 0; $i < $num_elements; $i++) {
will that bring any performance improvement or the number of elements of an array is stored internally ( in some scalar ) and there is no need to evaluate it again ?
Thanks again for the reply! :) | [reply] [d/l] [select] |
There's no significant speed difference. For both the scalar and the array, the get to the integer value from the SV or AV, one has to walk a pointer and add an offset.
It may even be that in the scalar case, perl checks IOK flag each time (to see whether it actually has a valid integer value), but that maybe optimized away.
Anyway, there isn't much of a reason to store the length of an array in a seperate variable.
| [reply] |