Perl Source Code: fread.pl
#!/usr/bin/perl
use CGI qw(:standard);
use common;
#----------------------------------------------------------
# The Web Language Project
# Mark Brautigam
# May-June 2015
# http://www.mixed-up.com/markb/
#----------------------------------------------------------
myUtils::headers1();
myUtils::headers2();
print myUtils::sidebar ("perl", "fread", "pl");
print <<middle;
<div id="content">
<h2>Perl: Display File Data Contents</h2>
<table class='results'>
<tr><th>College</th><th>Dept.</th><th>Course</th><th>Description</th><th>Edit</th></tr>
middle
#----------------------------------------------------
# The main Perl code is here.
#----------------------------------------------------
open (my $fh, "../data/courses.txt");
my @courses = <$fh>;
my $ncourses = @courses;
for ($i=0; $i<$ncourses; $i++) {
@coursedata = split (/\|/, $courses[$i]);
print ("<tr><td>$coursedata[0]</td><td>$coursedata[1]</td>" .
"<td>$coursedata[2]</td><td>$coursedata[3]</td>\n");
print ("<td><a href='fedit.pl?id=$i'><img src='../images/pencil.svg' /></a></td>\n");
print ("</tr>\n");
}
#----------------------------------------------------
print <<foot;
</table>
<p><a href='fwrite.pl'>Write to this file »</a></p>
<p><a href='source.pl?f=2'>Show Perl source code »</a>
</div>
foot
myUtils::footers();