use strict; #use warnings; use Data::Dumper; use XML::DOM; my $parser=new XML::DOM::Parser; my $doc = $parser->parsefile('C:\perl\perl_tests\AirbgICIndPer2.xml')o +r die$!; my $root=$doc->getDocumentElement(); print("Enter the number of flags which needs to be removed...\n\n"); my $num2=<STDIN>; if($num2>0) { for(my $p=0;$p<$num2;$p++) { print("type the signal id for which flags need to be removed..\n\n +"); my $sig_id=<STDIN>; print("type the flag name which needs to be removed according to t +he instructions\n\n"); print("State on flag remove : type StateOn\n"); print("Indication Function remove : type IndicationFunctions\n"); print("First value flags remove : type FirstValueFlags\n"); print("timeout notification flag remove : type TimeoutFlags\n\n"); my $flag_to_be_modified=<STDIN>; print("processing geny file data\n"); ClearSignalAttribute($sig_id,$flag_to_be_modified); } sub ClearSignalAttribute($$) { my $sigid=$_[0]; my $attribute=$_[1]; my $sigattributes; my $sig; my @attributes; my @signals; my $signal_id; $sig=$root->getElementsByTagName("signal")->item(0); $signal_id=$sig->getAttribute("sigid"); print("the input signal id is : $sigid\n"); print("the other signal id is : $signal_id\n"); if($sigid==$signal_id) { print("signal id matched\n"); if($sig->getElementsByTagName("attributes")) { $sigattributes=$sig->getElementsByTagName("attribu +tes")->item(0); @attributes=$sigattributes->getElementsByTagName(" +attribute"); print("got the attributes\n"); } foreach my $attr(@attributes) { my $a=$attr->getAttribute("name"); print("into the attribute array: $a\n"); my $c="VIlRx".$attribute; print("the target is : $c\n"); #if($attr->getAttribute("name") eq "VIlRx" +.$attribute) if($a eq $c) { print("attribute matched:$a\n"); if(my $temp1=$attr->getElementsByTagNa +me("item")->item(0)) { print("got the item element\n"); if(my $temp2=$temp1->getElementsBy +TagName("data")->item(0)) { print("got the data element\ +n"); if ($temp1->getAttribute("used +")=='1') { $b=$temp1->getAttribute("used" +); print("Attribute->used : $b\n" +); $temp1->setAttribute("used","0 +"); $temp1->setAttribute("order"," +-1"); $temp2->setAttribute("flags"," +4"); my $w=$temp1->getAttribute("us +ed"); my $x=$temp1->getAttribute("or +der"); my $y=$temp2->getAttribute("fl +ags"); print("used : $w\n"); print("order : $x\n"); print("flags : $y\n"); } } } } } } } #$doc->setXMLDecl($doc->createXMLDecl('1.0','UTF-8')); #$doc->printToFile("C:/perl/perl_tests/AirbgICIndPer2.xml"); } XML FILE : <?xml version="1.0" encoding="UTF-8"?> <ecuconfig id="1" name="ECU: IPC_LS" FrameworkVersion="1.4.48.0" Compa +tibleVersion="1.4.0.0"> <signal sigid="3464" id="3490"> <attributes> <creator name="Il_Vector_Gm"> <attribute name="Il_Vector_Gm_StateOn" typeid="3" value="1"/> </creator> <creator name="VectorIL"> <attribute name="VIlRxSigType" typeid="4" flags="4" set="0" value=""/> <attribute name="VIlRxSet" typeid="3" flags="1"/> <attribute name="VIlRxGet" typeid="3" flags="1"/> <attribute name="VIlRxRDS" typeid="3" flags="4" set="0" value="0"> <sharing flags="7" value="0"/> <textinfos> <textinfo fromid="3"> This attribute has been disabled by IL_Vector component.</textinfo> </textinfos> </attribute> <attribute name="VIlRxTimeoutTime" typeid="2" flags="4" set="0" value= +"0"/> <attribute name="VIlRxIndicationFlags" typeid="12" set="0"> <item index="0" order="-1" used="0"> <data typeid="4" flags="4" value="AirbgICIndPer"/> </item> </attribute> <attribute name="VIlRxIndicationFunctions" typeid="12" set="0"> <item index="0" order="0" used="1"> <data typeid="4" value="AirbgICIndPer"/> </item> </attribute> <attribute name="VIlRxFirstValueFlags" typeid="12" set="0"> <item index="0" order="0" used="1"> <data typeid="4" value="AirbgICIndPer"/> </item> </attribute> <attribute name="VIlRxDataChangedFlags" typeid="12" set="0"> <item index="0" order="-1" used="0"> <data typeid="4" flags="4" value="AirbgICIndPer"/> </item> </attribute> <attribute name="VIlRxTimeoutFlags" typeid="12" set="0"> <item index="0" order="0" used="1"> <data typeid="4" value="AirbgICIndPer"/> </item> <item index="1" order="1" used="1"> <data typeid="4" value="AirbgICIndPer_1"/> </item> </attribute> <attribute name="VIlRxTimeoutFunctions" typeid="12" set="0"> <item index="0" order="-1" used="0"> <data typeid="4" flags="4" value="AirbgICIndPer"/> </item> </attribute> <attribute name="VIlRxInitFunction" typeid="4" value=""/> <attribute name="VIlRxStartFunction" typeid="4" value=""/> <attribute name="VIlRxStopFunction" typeid="4" value=""/> <attribute name="VIlRxInitDefault" typeid="3" flags="1"/> <attribute name="VIlRxStartDefault" typeid="3" value="0"/> <attribute name="VIlRxStopDefault" typeid="3" value="0"/> <attribute name="VIlRxDefaultValue" typeid="4" flags="1"/> <attribute name="VIlRxTimeoutDefault" typeid="3" set="0" value="0"/> <attribute name="VIlRxTimeoutDefaultValue" typeid="4" flags="5"/> <attribute name="VIlRxTimeoutDynamicApi" typeid="3" flags="2" set="0" +value="0"> <sharing flags="7" value="0"/> </attribute> <attribute name="VIlRxRouting" typeid="3" flags="1"/> <attribute name="VIlRxTimeoutSupervisor" typeid="6" flags="4" orefid=" +1306"/> </creator> </attributes> <sources> <source srcid="19264"/> </sources> </signal> </ecuconfig>

I've written the above script to modify the various attributes of "item" and "data" element. when I try to run this script it is not showing any error but not performing the required actions. it is not going inside the loop "if($a eq $c)" and simply printing all the names ignoring this loop . any suggestions about what is the bug in this script and how I can handle it?:


In reply to How to Debug my perl script? by ankit.tayal560

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.