Posted on 2007-02-27 23:13:51-08 by liparig
Expand or evaluate contents of a string to get Data
Hi
Can someone please help me I am stuck and need help as soon as possible. What I am doing is trying to get data from an XML file using XML::Simple. The way to get the data is to do the setup (see below) then call $data->{$Project}->{FileName} to get the value of filename. What I want to do is have the user enter the name strings like "Project,FileName" as an argumenent when they call the perl function (For example: abc.pl "Project,FileName").

The problem is when I use a sting to build the full command so it looks like this:
$FullName = "$data->{$Project}->{FileName}";

Then try to print or store the filename value it does not work. I tried printing like this:
print ("FAIL:", $FullName, "\n");

Is there a command to tell Perl to evaluate or exand the string $FullName so the XML::Simple routines can work and get the value?


BELOW IS THE CODE I AM USING
----------------------------

#!/usr/bin/perl

# use module
use XML::Simple;
use Data::Dumper;

# create object
$xml = new XML::Simple (KeyAttr=>[]);

# read XML file
$data = $xml->XMLin("BC CALC Project0.xml");

#This one passes as it should
print ("PASS:", $data->{$Project}->{FileName}, "\n");

#but if I can to use a string it does not work
$FullName = "$data->{$Project}->{FileName}";
print ("FAIL:", $FullName, "\n");

THANK YOU
Joe
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.