Quote:
Originally Posted by
Raynon
Hi radoulov,
However, I am confused about the below array syntax.
Which is exactly the right one if we want to know the value.
@array[$num] VS $array[$num]
Certainly
$array[$index] is the correct way of referring to a single element of the array.
As a reminder, think of what you want to obtain; a single value, thus use the sigil $.
The other notation
@array[@index_list] is an array slice.
Here you usually want to get several array elements, thus use the sigil @.
Though
@array[$index] still would work, it is considered bad style
because you are after only a single element and thus there's no need for a slice.
As this is confusing a lot of Perl beginners, the language designers of Perl 6
I think will change the syntax to the sigil @ even when referring to a single element.
But I am not sure since Perl 6 is still work in progress.
And we only know that it will be out by Xmas, but we still don't know which Xmas.
But once it is out every day will be like Xmas.