IHYPRESS PROGRAMMING
Tutorials and Perl programs with code and output for beginners
Perl logo
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
Perl ❯ Arrays
<06>
#!/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>";
Hergestellt in Deutschland / Made in Germany
Arrays
yellow
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
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland