Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl `$[`, why base 42?

Tags:

perl

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?

like image 959
Filip Haglund Avatar asked Aug 24 '15 15:08

Filip Haglund


1 Answers

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.

like image 95
Marcus Müller Avatar answered Nov 08 '22 17:11

Marcus Müller