CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
writing formula in perl..

 



perl_zch
New User

Sep 26, 2012, 2:35 AM

Post #1 of 1 (1004 views)
writing formula in perl.. Can't Post

Hi,

I am new to perl. I am trying to parse my xml file to my script and generating an include or define file... My xml (test.xml) looks like:

<?xml version="1.0" encoding="UTF-8"?>
<DEFINES>
<TEST NAME="CHAIN_UNITS" VALUE="18"></TEST>
<TEST NAME="CHIP_UNITS" VALUE="33"></TEST>
<TEST NAME="MUX_WIDTH" VALUE="10"></TEST>
<TEST NAME="REGISTER_LENGTH" VALUE="9"></TEST>
<INSTANCES>
</INSTANCES>
<FUB></FUB>
<POWER_DOMAIN></POWER_DOMAIN>
<SECURITY></SECURITY>
</DEFINES>

My perl script is as:

#perl script

use strict; # Strict formatting
use warnings;
use Data::Dumper;
use XML::XPath;
use XML::XPath::XMLParser;
use Getopt::Long;
use Term::ANSIColor;

print "Hello world\n";

my $out="";
my $length="";
#create an object to parse the file
my $xp = XML::XPath->new(filename => 'test.xml');
my $nodeset =$xp->findnodes('/DEFINES/TEST');
$out.="//\n";
$out.="//\n";

foreach my $node( $nodeset->get_nodelist)
{
my $namenode=$node->getAttributeNode("NAME");
my $name=$namenode->getValue;
my $namelow=lc$name;

my $valuenode=$node->getAttributeNode("VALUE");
my $value=$valuenode->getValue;
my $valuelow=lc$value;

$out.="`define $name $value\n";
}

foreach my $node( $nodeset->get_nodelist)
{
my $namenode=$node->getAttributeNode("NAME");
my $name=$namenode->getValue;
my $namelow=lc$name;

my $valuenode=$node->getAttributeNode("VALUE");
my $value=$valuenode->getValue;
my $valuelow=lc$value;


$sdi_length="`define BOUNDARY_LENGTH ";
}

my $filename="./network/defines.sv";
open (FILE, "> $filename") or die ("Error: could not open file $filename for writing\n");
print FILE $out;
print FILE $length;
close FILE;

The formulae for calculating BOUNDARY_LENGTH is:

BOUNDARY_LENGTH = CHAIN_UNITS*MUX_WIDTH + CHIP_UNITS*MUX_WIDTH

My question here is that, How can I plug this formula into my script so that it gives me output in the file define.sv as "`define BOUNDARY_LENGTH 510". There is no error in the above script. Kindly help me in using this formula in my script.

Thanks.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives