in reply to What is txt2html and how does it work?

Time after time i hear "i can't use a CPAN module", but never do i hear why one can't use a CPAN module. But i will appease you nonetheless.

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:

open( T, "|/path/to/lib -l /path/to/.txt2html.dict" );
that will never work, because /path/to/lib is a directory. Surely you mean something like:
open( T, "|/path/to/txt2html.pl -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).

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:

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, ; }
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.

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
    never do i hear why one can't use a CPAN module.

    In this case it's not me, it's my friend. They want a quick solution to their problem, and their problem is cause by this particular thing, the library, which is embedded in their code. I could advise them to do it another way, but they really wouldn't.

    I promise to install CPAN modules where possible.

    OK your advice was very greatefully received:

    Surely you mean something like:

    open( T, "|/path/to/txt2html.pl -l /path/to/.txt2html.dict" );

    Yes, thanks for that. And thanks for your code. I uploaded it and ran it, and it worked.

    All I really want to do is tweak the regexes inside this script so that it doesn't attempt to find list items and convert them, and leave it in place in the rather awful structure it's in. So I wanted to install/use it so that I could test my regexes.
    --

    ($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;