This venerable variable demands more respect than many monks give it. Its might and glory are rarely actualized and this is a detriment to the perl community.
Observe this variables willingness to be noticed.
However, for the same reason this idiom is also wrong:
Evan Carroll
www.EvanCarroll.com
Observe this variables willingness to be noticed.
Take notice to 'print \$[;' not to be confused with '$[ = \$[; print $[;', but the fun doesn't stop here monks!$[++; # No go. $[+=1; # Not happening $[ = $[; # Works. $[ = $[ + 1; # That will work! print \$[; # Ok, works. $[ = \$[; # which also works print $[; # Whoo fun!
After playing with $[; I have taken note to this dire mistake that I apparently have made habit. And, now I have decided to publish a finding to enlighten all. This idiom is wrong, and must be corrected at all cost.$[=-1; @_=qw/foo bar baz/; print $_[-1]; # foo print $_[-2]; # bar print $_[-3]; # foo
#WRONG: for(my $i=0; $i<$#foo; $i++){} #RIGHT: for(my $i=$[; $i<$#foo; $i++){}
However, for the same reason this idiom is also wrong:
Now that two bad commonplace practices have been exposed, I suggest that we enable warnings to be issued for people who use the 0..$#foo. These willy-nilly coding practices are detrimental should be discouraged. I see them much more severe than addressing an element with the array sigil, at least Perl can correct for that.#WRONG: foreach(0..$#foo){} #RIGHT: foreach($[..$#foo){}
Evan Carroll
www.EvanCarroll.com
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: $[ is under respected.
by duff (Parson) on Aug 03, 2005 at 05:25 UTC | |
by jonadab (Parson) on Aug 03, 2005 at 11:32 UTC | |
by duff (Parson) on Aug 04, 2005 at 01:18 UTC | |
Re: $[ is under respected.
by tlm (Prior) on Aug 03, 2005 at 12:30 UTC | |
by Anonymous Monk on Aug 03, 2005 at 13:28 UTC | |
by spiritway (Vicar) on Aug 05, 2005 at 03:19 UTC | |
| |
Re: $[ is under respected.
by itub (Priest) on Aug 03, 2005 at 02:57 UTC | |
by EvanCarroll (Chaplain) on Aug 03, 2005 at 03:26 UTC | |
by Tanktalus (Canon) on Aug 03, 2005 at 03:32 UTC | |
by itub (Priest) on Aug 03, 2005 at 03:44 UTC | |
| |
| |
by itub (Priest) on Aug 03, 2005 at 03:51 UTC | |
Re: $[ is under respected.
by Anonymous Monk on Aug 03, 2005 at 09:05 UTC |
Back to
Meditations