Solved

Adding checkbox to perl output and how to search for strings in Perl

Posted on 2002-06-08
3
214 Views
Last Modified: 2010-03-05
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" ;
0
Comment
Question by:kpu8
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
jhurst earned 175 total points
ID: 7064994
If the only purpose is what you stated then, display the output lines in a form, since checkboxes can only be used in a form.  So the output lines would look something like:

for (...)
  print <<EOT;
<tr><td><input type="checkbox" name="whatever"></td>
<td>$_</td>
</tr>
  }

The tabel is not required, I just think it will look neater and it will handle the lin breaks for you.
0
 
LVL 1

Author Comment

by:kpu8
ID: 7120748
Maybe I didn't understand your snippet 100% - but when I add it into the code below - I get an internal server error:

#!/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" ;
0
 
LVL 1

Author Comment

by:kpu8
ID: 7744233
Thanks - this got me going - thought I closed this one out already - second one today which has been sitting around for a while - sorry
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now