in reply to Re^3: how internally $#array is working in Perl
in thread how internally $#array is working in Perl
If you write print 1/0; you don't expect a meaningful answer, right? Similarly you don't get a meaningful value in $a[0] if you tell perl that $a[0] doesn't exist
The correct way to handle access to index 0 would be to print an error message or warning. But that might break some really old scripts. So perl seems to print the same value that is in index 1, the first "legal" index.
And a word of advice: Don't change $[. And if you want to loop through an array, foreach (@a) {} will get you any value, no matter at what index the array begins and ends
|
|---|