#!/usr/bin/perl use strict; use warnings; # Ivan Novick # negative_subscript.pl # array subscripts can be negative numbers in perl my @fruits = ('apple', 'banana', 'cranberry', 'date', 'elderberry', 'fig', 'grape'); # use a range of numbers to test the subscripts # 0 1 2 3 4 5 6 for my $i ( 0 .. 6 ) { print "$i $fruits[$i]\n"; } # use a range of numbers in reverse to test the subscripts # -1 -2 -3 -4 -5 -6 -7 for my $j ( reverse(-7 .. -1) ) { # $fruits[-1] is the last element in the array # $frusts[-2] is the second to last element in the array # etc ... print "$j $fruits[$j]\n"; }