Solved

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

Posted on 2002-06-08
3
224 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
read PayflowPro reports using the report metadata using perl 11 43
Replace  text in a file 2 109
Regular Expression question to filter with negation. 6 96
Perl string filter 5 79
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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