Here is what I'm trying to do: I want the user to be able to print the text file one line at a time by clicking a button to see the next line.
Example: If text_file1 first line is line1 and the second line is line2, I want line1 to print when the user clicks the submit button then when they click it again line2 will be printed. Any help would be appreciated. If you need more information or an explanation please ask.
Expand|Select|Wrap|Line Numbers
- #! /usr/local/bin/perl
- BEGIN
- {
- open(STDERR, ">&STDOUT");
- select(STDERR); $| = 1;
- select(STDOUT); $| = 1;
- print qq{Content-type: text/html\n\n
- <title>Assignment #6 (CS Credit)</title>
- <body text="white" bgcolor="blue">
- <font face="arial" size="4">
- <div align="center">};
- }
- my $url = '/~westj2/cgi-bin/assignment6_CS_credit5.cgi';
- $buffer = $ENV{'QUERY_STRING'};
- if($buffer eq "")
- {
- &input;
- exit;
- }
- @pairs = split(/&/, $buffer);
- foreach $pair(@pairs)
- {
- ($name, $value) = split(/=/, $pair);
- $value =~ tr/+/ /;
- $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
- $name =~ tr/+/ /;
- $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
- if($FORM{$name} eq "")
- if($FORM{$name} eq "")
- {
- $FORM{$name} = $value;
- }
- else
- {
- $FORM{$name} .= " " . $value;
- }
- }
- my $linenum = 1;
- &hash;
- my $counter;
- if($FORM{'direction'} eq 'forward')
- {
- $counter = 1;
- }
- else
- {
- $counter = $linenum - 1;
- }
- &input;
- &output;
- sub input
- {
- print "<form method='get' action='$url'>";
- print "<b><font face='arial' color='white' size='3'><table
- align='center'><tr><td><b>Select a file to scan: </td><td><select name='filename'>";
- if($FORM{'filename'} eq 'Seinfeld')
- {
- my $filename = $FORM{'Seinfeld'};
- print "<option value='Seinfeld' SELECTED>Seinfeld</option>";
- print "<option value='Running_PRs'>Running PRs</option>";
- }
- else
- {
- $filename = $FORM{'Running_PRs'};
- print "<option value='Seinfeld'>Seinfeld</option>";
- print "<option value='Running_PRs' SELECTED>Running PRs</option>";
- }
- print "</select></td></tr><br><tr><td><b><font face='arial' color='white' size='3'>";
- if($FORM{'direction'} eq 'forward')
- {
- my $direction = $FORM{'forward'};
- print "<tr><td><b><font face='arial' color='white' size='3'><label for='forward'>Forward</label></td><td><input
- type='radio' name='direction' value='forward' CHECKED></td></tr><br>";
- print "<tr><td><b><font face='arial' color='white' size='3'><label for='reverse'>Reverse</label></td><td><input
- type='radio' name='direction' value='reverse'></td></tr><br>";
- }
- else
- {
- else
- {
- $direction = $FORM{'reverse'};
- print "<tr><td><b><font face='arial' color='white' size='3'><label for='forward'>Forward</label></td><td><input
- type='radio' name='direction' value='forward'></td></tr><br>";
- print "<tr><td><b><font face='arial' color='white' size='3'><label for='reverse'>Reverse</label></td><td><input
- type='radio' name='direction' value='reverse' CHECKED></td></tr><br>";
- }
- print "</table><p align='center'><input type='submit'
- name='submit' value='Submit'><input type='reset'
- value='Reset'></form>";
- }
- sub hash
- {
- open(file, "<$FORM{'filename'}") || die "Cannot open file: $!\n";
- my $line;
- # my $linenum = 1;
- while($line = <file>)
- {
- $hash{$linenum} = $line;
- $linenum++;
- }
- }
- sub output
- {
- print "$hash{$counter}";
- if($FORM{'direction'} eq 'forward')
- {
- # $line = $linenum - 1;
- $counter++;
- }
- else
- {
- $counter--;
- }
- }