Extraction problem with Template::Extract
jfroebe
created: 2006-04-03 14:21:26

Hi,

I'm trying to use Template::Extract to extract data out of a string.

#!/usr/bin/perl

use strict;
use warnings;

use Template::Extract;

my $template = <new();
my $data = $template_extract->extract($template, $doc);

use Data::Dumper;
print Dumper($data);
print $template;

The problem is that it isn't capturing the 'alloc_pg' at the end of each line. Obviously, it is something simple...

$VAR1 = {
          'records' => [
                         {
                           'alloc_pg' => '',
                           'extent_id' => '608',
                           'oampg' => '600'
                         },
                         {
                           'alloc_pg' => '',
                           'extent_id' => '616',
                           'oampg' => '128'
                         }
                       ]
        };
[% FOREACH records %]
[% ... %]
 OAMPG: [% oampg %]   Extent ID [% extent_id %] on allocation page [% alloc_pg %]
[% END %]

Any ideas?

Jason L. Froebe

Team Sybase member

No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Re: Extraction problem with Template::Extract
created: 2006-04-04 11:00:58
You'll need to version 0.40 for this to work:
use Template::Extract;

my $template = <<'EOD';
[% FOR records %]
[% ... %]
 OAMPG: [% oampg %]   Extent ID [% extent_id %] on allocation page [% alloc_pg =~ /(\d+)/%]
[% END %]
EOD

my $doc = <new->extract($template, $doc));
I'm not sure what the exact problem is with [cpan://Template::Extract] but I suspect it is because it needs a trailing token for the match to halt.
HTH

_________
broquaint

Re^2: Extraction problem with Template::Extract
created: 2006-04-04 14:50:09

That makes sense... I'm glad it isn't my brain sans caffeine that is the issue ;-)

Jason L. Froebe

Team Sybase member

No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

perlmonks.org content © perlmonks.org and broquaint, jfroebe

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03