[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Text based stage play scripts to XML

Subject: Re: Text based stage play scripts to XML
From: Jacobus Reyneke <jacobusreyneke@xxxxxxxxx>
Date: Mon, 24 Jan 2011 21:44:23 +0200
Re:  Text based stage play scripts to XML
> #! /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/"/\&quot;/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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.