kpu8
asked on
Adding checkbox to perl output and how to search for strings in Perl
In the following code - I'm opening a text file and displaying it's contents - now I want to add a html checkbox to have the abaility to flag rows (how in the world can this be done
Also in perl how can a serach for a string - ideally I'd like to have a <br> after the word EDT in the txt file:
I'm not a perl guru by any means - this is likely easy
but I just don't use the language enough to know it cold:
#!/usr/bin/perl5
#
# Read in the data file
# Print out a HTML formatted lines
#
$file = 'register.txt' ; # Name the file
open(INFO, "<$file") ; # Open the file
@lines = <INFO> ; # Read it into an array
close(INFO) ; # Close the file
$long_line = join("\n", @lines ) ; # Convert array to variable
# retaining end-of-line characters
@dash_sep = split ( /---------/, $long_line ) ; # split long_line at dashes
print "Content-Type: text/html\n\n";
print "<HTML> <HEAD> <TITLE> PERL output </TITLE> </HEAD>\n" ;
print " <BODY>\n" ;
foreach $line (@dash_sep) # assign @dash_sep to $line, one at a time
{
$line =~ s/line of text./text fragment. /g ; # substitute text
$line =~ s/\n//g ; # remove end of line characters
if ($line =~ /^A third text/ ) # test for 3rd text fragment
{
print " <HR> <BR> \n" ;
}
print " <P> $line </P> \n" ;
}
print " </BODY>\n</HTML>\n" ;
Also in perl how can a serach for a string - ideally I'd like to have a <br> after the word EDT in the txt file:
I'm not a perl guru by any means - this is likely easy
but I just don't use the language enough to know it cold:
#!/usr/bin/perl5
#
# Read in the data file
# Print out a HTML formatted lines
#
$file = 'register.txt' ; # Name the file
open(INFO, "<$file") ; # Open the file
@lines = <INFO> ; # Read it into an array
close(INFO) ; # Close the file
$long_line = join("\n", @lines ) ; # Convert array to variable
# retaining end-of-line characters
@dash_sep = split ( /---------/, $long_line ) ; # split long_line at dashes
print "Content-Type: text/html\n\n";
print "<HTML> <HEAD> <TITLE> PERL output </TITLE> </HEAD>\n" ;
print " <BODY>\n" ;
foreach $line (@dash_sep) # assign @dash_sep to $line, one at a time
{
$line =~ s/line of text./text fragment. /g ; # substitute text
$line =~ s/\n//g ; # remove end of line characters
if ($line =~ /^A third text/ ) # test for 3rd text fragment
{
print " <HR> <BR> \n" ;
}
print " <P> $line </P> \n" ;
}
print " </BODY>\n</HTML>\n" ;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks - this got me going - thought I closed this one out already - second one today which has been sitting around for a while - sorry
ASKER
#!/usr/bin/perl5
#
# Read in the data file
# Print out a HTML formatted lines
#
$file = 'register.txt' ; # Name the file
open(INFO, "<$file") ; # Open the file
@lines = <INFO> ; # Read it into an array
close(INFO) ; # Close the file
$long_line = join("\n", @lines ) ; # Convert array to variable
# retaining end-of-line characters
@dash_sep = split ( /---------/, $long_line ) ; # split long_line at dashes
print "Content-Type: text/html\n\n";
print "<HTML> <HEAD> <TITLE> PERL output </TITLE> </HEAD>\n" ;
print " <BODY>\n" ;
foreach $line (@dash_sep) # assign @dash_sep to $line, one at a time
{
$line =~ s/line of text./text fragment. /g ; # substitute text
$line =~ s/\n//g ; # remove end of line characters
if ($line =~ /^A third text/ ) # test for 3rd text fragment
{
print " <HR> <BR> \n" ;
}
print " <p>$line</p> \n" ;
}
{
print <<EOT;
<tr><td><input type="checkbox" name="whatever"></td>
<td>$_</td>
</tr>
}
print " </BODY>\n</HTML>\n" ;