Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2002-06-08
3
Medium Priority
?
250 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 700 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans

916 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