Perl had $[ (yes, just those two characters) to allow setting of the first array index, but it’s a fatal error to put anything but 0 into it now.
Of course, since Perl arrays can be negative subscripted from the last element, you can stand on your head and index the array negatively from the wrong end. -1, -2, -3 etc. Use unshift to put things on the beginning (logical “end”) of what you’re doing rather than the usual push. Presto, a 1-based array (up to sign, anyway).
You may wish to file this under “stupid, but it works”.
People with more time / more need for something that looks professional, would probably be better off writing something that uses tie instead. (Or, yes, yes, a different language entirely, hush now.)
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmerhumor@lemmy.ml
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
Posts must be relevant to programming, programmers, or computer science.
No NSFW content.
Jokes must be in good taste. No hate speech, bigotry, etc.
Perl had
$[
(yes, just those two characters) to allow setting of the first array index, but it’s a fatal error to put anything but 0 into it now.Of course, since Perl arrays can be negative subscripted from the last element, you can stand on your head and index the array negatively from the wrong end. -1, -2, -3 etc. Use
unshift
to put things on the beginning (logical “end”) of what you’re doing rather than the usualpush
. Presto, a 1-based array (up to sign, anyway).You may wish to file this under “stupid, but it works”.
People with more time / more need for something that looks professional, would probably be better off writing something that uses
tie
instead. (Or, yes, yes, a different language entirely, hush now.)Thanks I hate it.
But still better than mathlab not allowing 0 indexed arrays.