Solved

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

Posted on 2002-06-08
3
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

751 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