#!/usr/bin/perl -wT
use CGI':standard';
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
my @colours;
my $colour;
my @cities;
@colours = ("red ", "green ", "blue ", "yellow ", "white ", "black ");
@cities = ("Berlin ", "Munich ", "Stuttgart ", "Hamburg ", "Frankfurt ");
print "Content-type: text/html\n\n";
print "<!DOCTYPE html>";
print "<html><head>";
print "<title>Arrays</title>";
print "<style>div.out {margin-top:10px; font-size:24px; font-family:sans-serif;}</style>";
print "</head><body>";
#printing an array element
print "<div class='out' style='color:Coral;'>";
print $colours[3];
print "</div>";
#printing the whole array
print "<div class='out' style='color:FireBrick;'>";
print @colours;
print "</div>";
#getting the first element into a variable
($colour) = @colours;
print "<div class='out' style='color:SeaGreen;'>";
print $colour;
print "</div>";
#adding an element at the end of an array
push (@colours, "orange ");
print "<div class='out' style='color:Orange;'>";
print @colours;
print "</div>";
#adding an element at the beginning of an array
unshift (@colours, "cyan ");
print "<div class='out' style='color:Salmon;'>";
print @colours;
print "</div>";
#reversing an array
reverse (@cities);
print "<div class='out' style='color:SaddleBrown;background-color:BurlyWood;'>";
print @cities;
print "</div>";
#splicing an array
splice (@cities,2,2);
print "<div class='out' style='color:Teal;background-color:Aquamarine;'>";
print @cities;
print "</div>";
print "</body></html>";
Arraysyellow
red green blue yellow white black
red
red green blue yellow white black orange
cyan red green blue yellow white black orange
Berlin Munich Stuttgart Hamburg Frankfurt
Berlin Munich Frankfurt