in reply to What array negative number counting means

If you want to access the last element of an array, it's fewer keystrokes to do $x[-1], or $x[-2] for second last, etc.
It's also clearer, IMO.
But if you prefer to do $x[(scalar @x) - y], then that's ok.
That's about it ... TIMTOWTDI.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: What array negative number counting means
by Anonymous Monk on Jul 27, 2020 at 23:56 UTC
    Could you please explain to me what $x[(scalar @x) - y] is doing?
      (scalar @x) is the length of @x here 3

      (scalar @x) - 1 == 2

      In other words

      $x[-y] is a shortcut for $x[(scalar @x) - y]

      =>

      $x[-1] eq $x[2] eq "light"

      $x[-2] eq $x[1] eq "bar"

      $x[-3] eq $x[0] eq "foo"

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Thank you very much. :-)