in reply to it is amazing sometimes how little you know...
$ARRAY[-1] is the same as
@ARRAY[(scalar @ARRAY) -1] (actual code from one of my early scripts ;)