Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Template::Extract module query

Status
Not open for further replies.

tar565

Programmer
Jan 24, 2005
39
IE
Firstly thank you for all your info on my previous query.
I have come accross the Template::Extract module which will make my life a lot easier when extracting data. The module is present, but when I run the following sample code I get the following error:

###########################################################

Can't find string terminator "." anywhere before EOF at Data_Dumper.pl line 17.

###########################################################

#!/usr/bin/perl

# turn on perl's safety features
use strict;
use warnings;

# create a new template extractor
use Template::Extract;
my $extract = Template::Extract->new();

# get the source of the page
use LWP::Simple qw(get);
my $document = get " or die "Can't get page";

# define the template
my $template = << ".";
<a href="city.html?n=[% ... %]">[% city %]
</a></td><td class=r>[% time %]</td>
.

# extract the data
my $data = $extract->extract($template, $document);
# print it out so we can see we've got what we want to
use Data::Dumper;
print Dumper $data;
 
It's hard to see from the post, but is the '.' that terminates the here-document in column 1 ?

I hate here-documents for this reason. Can't you just put the template in a string variable?
 
my $template = << ".";

this doesn't look right, also the full stop after the

<a href="city.html?n=[% ... %]">[% city %]
</a></td><td class=r>[% time %]</td>
. <- this one

HTH
--Paul

cigless ...
 
Yes I agree that it doesn't look right but I get the exact same error from the exmaple on the CPAN page.
 
Code:
 use Template::Extract;
    use Data::Dumper;

    my $obj = Template::Extract->new;
    my $template = << 'EOF';
    <ul>[% FOREACH record %]
    <li><A HREF="[% url %]">[% title %]</A>: [% rate %] - [% comment %].
    [% ... %]
    [% END %]</ul>
EOF

    my $document = << 'EOF';
    <html><head><title>Great links</title></head><body>
    <ul><li><A HREF="[URL unfurl="true"]http://slashdot.org">News[/URL] for nerds.</A>: A+ - nice.
    this text is ignored.</li>
    <li><A HREF="[URL unfurl="true"]http://microsoft.com">Where[/URL] do you want...</A>: Z! - yeah.
    this text is ignored, too.</li></ul>
EOF

    print Data::Dumper::Dumper(
        $obj->extract($template, $document)
    );

The "." needs to be be at the start of the line, sorry didn't recognise the construct because of using the period

HTH
--Paul

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top