in reply to What is txt2html and how does it work?
First, you are correct, that is not a module or a library. It is a Perl script, which IMHO is a horrible way to solve this problem. Better would be to make a library, but then again, since you can't use CPAN module, you surely couldn't use a library. ;)
Piping works by attaching the output of one process to the input of another process, or vice versa. So, in this example, you fork and exec another process to invoke another Perl script. This is overkill. A better way is to use a library or module that you use or require subroutines into your CGI script's namespace.
Why doesn't it work? Well, if you are using this line verbatim:
that will never work, because /path/to/lib is a directory. Surely you mean something like:open( T, "|/path/to/lib -l /path/to/.txt2html.dict" );
because you are going to execute the script in question, not import it into your CGI script's namespace. What can you check? Run everything in quotes (except the leading pipe, of course) from the open in a shell first. This is a sane way to ensure that a) the script to execute is executable (chmod 755) and b) the dictionary file is readable (chmod 644).open( T, "|/path/to/txt2html.pl -l /path/to/.txt2html.dict" );
I got the example to work. I copied (as root) txt2html.pl to /usr/bin/txt2html and copied txt2html.dict to my public_html directory for user 'jeffa'. I modified the CGI script to actually ask the user for some text to mark up:
And it worked fine. But, i still recommend you use HTML::FromText or HTML::TextToHTML. If you can download and install a solution that forks and execs to another script, you can download and install a CPAN module. If you feel that you can't install modules due to permissions, correct this misinformation by reading this excellent Guide to Installing Modules.use strict; use CGI qw(:standard); print header; my $text; if ($text = param('text')) { open(T, "|/usr/bin/txt2html -l /home/jeffa/public_html/txt2html.dic +t"); print T $text; } else { print start_html, start_form, textfield('text'), submit, end_form, end_html, ; }
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: txt2html
by Cody Pendant (Prior) on Jul 16, 2002 at 04:45 UTC |