in reply to Re: What array negative number counting means
in thread What array negative number counting means

Could you please explain to me what $x[(scalar @x) - y] is doing?
  • Comment on Re^2: What array negative number counting means

Replies are listed 'Best First'.
Re^3: What array negative number counting means
by LanX (Saint) on Jul 28, 2020 at 00:16 UTC
    (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. :-)