#!/usr/bin/perl -wT
use CGI':standard';
use strict;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
my @colors;
my $color;
@colors = ("red ", "green ", "blue ", "yellow ", "white ", "black ");
print "Content-type: text/html\n\n";
print "<!DOCTYPE html>";
print "<html><head><title>Arrays</title></head>";
print "<body>";
#printing an array element
print "<div style='color:blue;font-size:1.2em;'>";
print $colors[3];
print "</div>";
#printing the whole array
print "<div style='color:red;font-size:1.2em;'>";
print @colors;
print "</div>";
#getting the first element into a variable
($color) = @colors;
print "<div style='color:#006600;font-size:1.2em;'>";
print $color;
print "</div>";
#adding an element at the end of an array
push (@colors, "orange ");
print "<div style='color:#cc00cc;font-size:1.2em;'>";
print @colors;
print "</div>";
#adding an element at the beginning of an array
unshift (@colors, "cyan ");
print "<div style='color:#006666;font-size:1.2em;'>";
print @colors;
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
COPYRIGHT © 2015-2024 IHYPRESS.NET. A DIVISION OF IHY PRESS. ALL RIGHTS RESERVED.