# File: array0.pl # Title: Arrays in Perl. Array (@) # Arrays are lists of scalars. Array names begin with @. # Author: Mihaela Malita # Declare an array X @X = (7,3,2,5); # 5 is Last, out with POP print "Array is ", @X; $first = @X[0]; $second = @X[1]; @NewX = ($first, $first); #take First and put it twice print "\nNew Array: ", @NewX; $len = @X; print "\nLength array X= ", $len,"\n"; # lenght array for (@X) { print $_, "\n"; #print each element on a different line } pop @X; # last is out print "\nafter pop X= ", @X; # 7 3 2 push (@X,9); # add at the end print "\nafter push 9 X= ", @X; # 7 3 2 9 @M = reverse @X; print "\nPrint Reversed ", @M; # 9 2 3 7 @M = (@M,@M); print "\nAfter putting arrays together ", @M; # 9 2 3 7 9 2 3 7 @Y = ('a', 2012, 'Three'); print "\nFirst element in array @Y= ",$Y[0]; # This prints a $Y[2] = 'YYY'; # new value for index 2 element print "\nY = ", @Y; # Y = a2012YYY exit;