in reply to Re: how internally $#array is working in Perl
in thread how internally $#array is working in Perl
From perlvar:
I suspect you can assign 1 to it, but other values are silently ignored. I tried your code with $[=1, and lo and behold:$[ The index of the first element in an array, and of the first character + in a substring. Default is 0, but you could theoretically set it to 1 to ma +ke Perl behave more like awk (or Fortran) when subscripting and when evaluatin +g the index() and substr() functions. (Mnemonic: [ begins subscripts.) As of release 5 of Perl, assignment to $[ is treated as a compiler dir +ective, and cannot influence the behavior of any other file. (That's why you can o +nly assign compile-time constants to it.) Its use is deprecated, and by default w +ill trigger a warning. Note that, unlike other compile-time directives (such as strict), assi +gnment to $[ can be seen from outer lexical scopes in the same file. However, yo +u can use local() on it to strictly bind its value to a lexical block.
(shrug)perl -le '@arr=qw(10 1 2 3 4);$[=1;print $arr[$_],"\t",$_ for 0 .. $#a +rr;' 10 0 10 1 1 2 2 3 3 4 4 5
SSF
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: how internally $#array is working in Perl
by DrHyde (Prior) on Aug 13, 2010 at 09:59 UTC | |
by ikegami (Patriarch) on Aug 13, 2010 at 13:53 UTC | |
by DrHyde (Prior) on Aug 16, 2010 at 09:51 UTC | |
by Corion (Patriarch) on Aug 16, 2010 at 09:55 UTC | |
Re^3: how internally $#array is working in Perl
by nvivek (Vicar) on Aug 13, 2010 at 08:50 UTC | |
by jethro (Monsignor) on Aug 13, 2010 at 09:34 UTC |
In Section
Seekers of Perl Wisdom