You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Pierre Etchemaïté <pe...@concept-micro.com> on 2000/12/14 12:35:00 UTC
HTML::Embperl::Execute modifying 'output' only once
Hi All, hi Gerald,
I wrote some code for a forum, that displays user entered text,
turning all URLs found into real links. Here it is:
[- @t = split(/\x0d\x0a/, $message); $r = '';
{
local $/ = "\x0d\x0a"; # for chomp below
for($i=0;$i < scalar @t;$i++) {
$out = ''; $t = $t[$i];
HTML::Embperl::Execute({'escmode' => 1,
'input' => \$t,
'output' => \$out,
'mtime' => undef});
chomp $out;
$out =~ s@((?:ftp|http|news)://[^ ]*[^ .,:;!?<>()])@<A
HREF="$1">$1</A>@gi;
$r .= "<BR>\n" if $r;
$r .= $out;
}
} -]
[+ local $escmode=0; $r +]
It may not be optimal, but it works well. I tried to put that code in
a Perl module, since it looks quite reusable:
package XXX;
use strict;
use lib qw(..);
use Exporter ();
use HTML::Embperl ();
use vars qw(@ISA @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(UserText);
sub UserText($) {
my($Text) = @_;
{
local $/ = "\x0d\x0a"; # for chomp below
return join("<BR>\n",
map { my $out;
HTML::Embperl::Execute({'escmode' => 1,
'input' => \$_,
'output' => \$out,
'mtime' => undef});
chomp $out;
$out =~ s@((?:ftp|http|news)://[^ ]*[^ .,:;!?<>()])@<A
HREF="$1">$1</A>@gi;
$out }
split(/\x0d\x0a/, $Text)
);
}
}
1;
When called from command-line using a Perl script, all seems fine.
Re: HTML::Embperl::Execute modifying 'output' only once
Posted by Gerald Richter <ri...@ecos.de>.
>
> I wrote some code for a forum, that displays user entered text,
> turning all URLs found into real links. Here it is:
>
> [- @t = split(/\x0d\x0a/, $message); $r = '';
> {
> local $/ = "\x0d\x0a"; # for chomp below
> for($i=0;$i < scalar @t;$i++) {
> $out = ''; $t = $t[$i];
> HTML::Embperl::Execute({'escmode' => 1,
> 'input' => \$t,
> 'output' => \$out,
> 'mtime' => undef});
> chomp $out;
> $out =~ s@((?:ftp|http|news)://[^ ]*[^ .,:;!?<>()])@<A
> HREF="$1">$1</A>@gi;
> $r .= "<BR>\n" if $r;
> $r .= $out;
> }
> } -]
> [+ local $escmode=0; $r +]
>
>
> It may not be optimal, but it works well. I tried to put that code in
> a Perl module, since it looks quite reusable:
>
> package XXX;
> use strict;
> use lib qw(..);
> use Exporter ();
> use HTML::Embperl ();
> use vars qw(@ISA @EXPORT_OK);
> @ISA = qw(Exporter);
> @EXPORT_OK = qw(UserText);
>
> sub UserText($) {
> my($Text) = @_;
> {
> local $/ = "\x0d\x0a"; # for chomp below
> return join("<BR>\n",
> map { my $out;
> HTML::Embperl::Execute({'escmode' => 1,
> 'input' => \$_,
> 'output' => \$out,
> 'mtime' => undef});
> chomp $out;
> $out =~ s@((?:ftp|http|news)://[^ ]*[^ .,:;!?<>()])@<A
> HREF="$1">$1</A>@gi;
> $out }
> split(/\x0d\x0a/, $Text)
> );
> }
> }
>
> 1;
>
Why do you Execute every line spepartely? Why not just process the while
file at once. That will be much faster...
> It looks like HTML::Embperl::Execute() only modifies $out during the
> first loop.
>
You should give a name to your code for Embperl cache management. Try to add
the inputfile parameter and set it a any value
HTML::Embperl::Execute({'escmode' => 1,
'input' => \$_,
'output' => \$out,
'inputfile' => 'mycode'});
Also you can leave out the mtime => undef (but it doesn't hurt)
Gerald
-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting
Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925131
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------