Trying to parse a variable name

From: Aaron (naunga_at_hotmail.com)
Date: 08/17/04


Date: 17 Aug 2004 09:34:32 -0700

Basically I'm reading a SQL predicate from an XML file. The predicate
contains a perl variable name.

I have a sub called parseValue that takes a literal string and then
returns the value.

Now, if I pass in a qq{} or ' ' quoted string it works fine, but when
I pass in the value from the XML file it doesn't work.

I should get the following output:

PARSED STRING: ENGINE_ID = 1
PARSED STRING: ENGINE_ID = 1

But I get the following:

PARSED STRING: ENGINE_ID = 1
PARSED STRING: ENGINE_ID = &parseValue($engine_id)

What the heck is going on?

I've included the code and the XML file below.

#!/usr/bin/perl

use XML::Simple;
use Data::Dumper;

$engine_id = 1;

sub parseValue
{
        my $value = shift;

        $value =~ s/\$(\w+)/${$1}/;

        return $value;
}

print "PARSED VALUE: ",&parseValue('$engine_id'),"\n";

sub BySequence
{
        $transforms->{Transform}->{$a}->{Sequence} <=>
$transforms->{Transform}->{$b}->{Sequence}
}

$transforms = XMLin("test.xml",forcearray => ["Transform"]);

foreach $transform (sort BySequence keys %{$transforms->{Transform}})
{
        %transform = %{$transforms->{Transform}->{$transform}};

        $delete_predicate = $transform{DeletePredicate};

        print "$delete_predicate\n";
        $delete_predicate =~ s/(\$\w+)/&parseValue($1)/g;
        print "$delete_predicate\n";

        %transform = ();
}

<?xml version="1.0" ?>
<Transforms>
        <Transform Sequence="1" name="Planned Order">
                <DeletePredicate>ENGINE_ID =
$engine_id</DeletePredicate>
        </Transform>
</Transforms>



Relevant Pages

  • Trying to parse a variable name
    ... Basically I'm reading a SQL predicate from an XML file. ... I have a sub called parseValue that takes a literal string and then ... PARSED STRING: ENGINE_ID = 1 ...
    (comp.lang.perl.misc)
  • public shared object... and disappearing xml content in file
    ... It is created from an xml file stored on disk. ... Public Sub New ... Private Sub Button1_Click(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: How do I do these dynamic links in ASP.NET ?
    ... The community starter kit has a well-setup breadcrump component (but it's ... The way I've always seen it set up is via a user control which you include ... The user control would then be fed off an XML file ... I had an include file which included a Sub like ...
    (microsoft.public.dotnet.framework.aspnet)
  • Need some problemsolving-cgi/xml
    ... then it executes a query ... then transform the xml file via xsl file to output in the browser. ... sub start_handler ...
    (comp.lang.perl.misc)
  • Need some problemsolving-cgi/xml
    ... - then it executes a query ... - then transform the xml file via xsl file to output in the browser. ... sub start_handler ...
    (comp.lang.perl.misc)