7

I found this part of an answer really confusing. Most of the answers are special cases of some basic rules, such as the "333" + "222" == "333222" but "333" - "222" = 111 of javascript, where using + for string concatenation is useful.

$[ — change your array base from 0-based to 1-based to 42-based: WHEEE!

What's the use case for 42-based array indexing? Just a Hitchhiker's guide to the galaxy reference / incredibly evil easter egg, or actually useful?

Filip Haglund
  • 13,919
  • 13
  • 64
  • 113
  • 8
    `$[` can be used to set other bases, too; the commenter was almost certainly (a) ridiculing the "feature" and (b) making an HHGTTG reference. – Paul Roub Aug 24 '15 at 15:30

1 Answers1

12

If you do

$[ = 42

you set the "base" of your array indexing to 42; so the first element of an array can be requested by doing

$something[42]

instead of

$something[0]

Obviously this is immensely helpful if you want to, or you need to, or your is just that but also can't. Therefore, it was deprecated to the ninth circle of deprecation hell.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • @ikegami: sorry, I don't follow. – Marcus Müller Aug 24 '15 at 15:53
  • 3
    Your choice to link to an essay written in support of adding `$[` to another language is interesting, though it does mention that "`$[` is not just deprecated, it is dissed" in Perl5. – ikegami Aug 24 '15 at 15:59
  • If you happen to have a more precise document where `$[` gets deprecated, I'd ask you to just modify the link in my answer. – Marcus Müller Aug 24 '15 at 16:11
  • It would be in one of the .0 perldelta. I'm too exhausted to look it up right now. – ikegami Aug 24 '15 at 16:16
  • 1
    [Deprecated in 5.12.0](http://perldoc.perl.org/perl5120delta.html#Assignment-to-%24[), although there are no details beyond "Assignment to `$[`". Also documented in [perlvar](http://perldoc.perl.org/perlvar.html#%24[) under "Deprecated and removed variables." – ThisSuitIsBlackNot Aug 24 '15 at 16:35
  • In [5.16](http://perldoc.perl.org/perl5160delta.html) it get disabled and moved into a feature. Not sure about the deprecation warning if you turn it on. "$[ is now disabled under use v5.16 . It is part of the default feature set and can be turned on or off explicitly with use feature 'array_base' ." – simbabque Aug 24 '15 at 16:35