#!/usr/bin/perl
require CGI;
use CGI;
my $cgi = new CGI;
my $passno=$cgi->param('passno');
my $emails=$cgi->param('emails');
my $last;
my @list=('a','b','c');
my %hash=('first','a','second','b','third','c');
my $list='abc';
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<h2 align=\"center\">Using Pointers in PERL</h2>";
print "<h3 align=\"center\">Holy moly scalers</h3>";
#
# print a scaler variable inline
#
print "\$list=$list<br>\n";
#
# use a function to print a scaler item
#
&dumpscaler($list);
print "<h3 align=\"center\">My god an array</h3>";
#
# print a @list variable inline
#
foreach(@list) {
print "$_<br>\n";
}
#
# use a function to print a @list item
# notice a \ preceeds the @ as \@
#
&dumparray(\@list);
print "<h3 align=\"center\">By Jove a hash</h3>";
#
# print a @hash variable inline
#
foreach(keys(%hash)) {
print "$_->$hash{$_}<br>\n";
}
#
# use a function to print a %hash item
# notice a \ preceeds the % as \%
#
&dumphash(\%hash);
#
# print this stupid program
#
$rc=dump_program();
#
# get outta here! we are all done!
#
exit;
#
# a function to dump a scaler variable
#
sub dumpscaler {
my $rc=0;
my $data=@_[0];
print "\$data=$data<br>\n";
return $rc;
}
#
# a function to dump an array variable
#
sub dumparray {
my $rc=0;
my $data=@_[0];
print "\$data=$data<br>\n";
#
# notice @$ is used to point to the array
#
foreach(@$data) {
print "list($_)<br>\n";
}
return $rc;
}
#
# a function to dump an hash variable
#
sub dumphash {
my $rc=0;
my $data=@_[0];
print "\$data=$data<br>\n";
#
# notice that %$ is used to point to the hash
#
foreach(keys(%$data)) {
print "$_->$hash{$_}<br>\n";
}
return $rc;
}
sub dump_program {
$rc=0;
#
# print the stinking title
#
print "<h2 align=\"center\">List the code that did this!</h2>";
#
# enclose the data in a blockquote so it is endented
#
print "<blockquote>";
#
# and print it in PRE mode so it shows up exactly as typed
#
print "<pre>";
#
# open the file to print
#
open CODE, "<", 'perl_pointers.pl';
#
# read and print each line in the file
#
while(<CODE>) {
#
# change any & characters to &
#
s/&/&/g;
#
# change any > characters to >
#
s/>/>/g;
#
# change any < characters to <
#
s/</</g;
#
# print the next line of code
#
print $_;
}
#
# close the file
#
close(CODE);
print "</pre>";
print "</blockquote>";
#
# return to the caller
# christians say get the flock outta here
#
return $rc;
}