Some basic perl programming constructs that can be implemented in HTML/CGI web pages
Basic While loop
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
print "content-type: text/html \n\n";
# SET VARIABLE(S)
my $count = 0;
# RUN WHILE LOOP
while ($count <= 10) {
# PRINT RESULT
print "$count ";
# INCREMENT VARIABLE
$count ++;
}
print "While loop complete!";
While loop with conditional statement (using next)
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
print "content-type: text/html \n\n";
# SET VARIABLE(S)
my $count = 0;
while ($count <= 10) {
# CONDITIONAL STATEMENT - Skip 5
if ($count == 5) {
print "Five skipped! ";
next;
}
# PRINT THE COUNTER
print $count." ";
}
continue {
$count++;
};
print "Loop Finished!";
While loop, arrays, using Dumper, - create a html table
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
print "content-type: text/html \n\n";
# Create an ARRAY
my @names = qw(Perl Javascript Linux DOS);
# VARIABLE(S)
my $count = 1;
my $n = 0;
my $temp = @names;
my $tempPointer = \@names;
print "print var temp scalar value:- $temp