#! /usr/bin/perl -w
use warnings;
use strict;
sub element($$;%)
{
my ($name, $content, %attributes) = @_;
sub quotedattvalue($$)
{
my ($name, $value) = @_;
# print STDERR "q $name, $value\n";
$value =~ s/"/\"/g; # so we can safely use quotes
return '"' . $value . '"';
}
# make a list of att="value" pairs, each with a leading space:
# (could use join and map to do this too more succinctly,
# see perldoc -f map)
my $atts = "";
if (%attributes) {
foreach (keys %attributes) {
$atts .= " " .
$_ . '=' . quotedattvalue($_, $attributes{$_})
;
}
}
return "<${name}${atts}>${content}</${name}>";
}
my $text;
{
local $/;
$text = <>;
};
$text =~ s{c d\K e f (?=g h)}{
element(
"found-you",
$&,
"rule" => "31",
"before" => "c d"
)
}gme;
print $text;
# end
Liam, you are a genius. The effort and passion you put into your
response is commendable! Thanks a stack. I'm working it through. Since
the nlptk (natural language processing toolkit) is written in Python,
I assumed for some reason that Python was better suited for text
processing in a modern world - but Perl seems quite readable, logical
and practical.
Thanks again for the effort! And friendly "hello world" in Perl.
Kind regards,
Jacobus
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--