I have a package.xml
file which has the following structure:-
<package name="com/avinash/foo1">
<sourcefile name="bar1.java">
<line no="1" mi="3"/>
<line no="3" mi="2"/>
</sourcefile>
<sourcefile name="bar2.java">
<line no="1" mi="5"/>
<line no="6" mi="8"/>
<line no="7" mi="3"/>
</sourcefile>
</package>
<package name="com/avinash/foo2">
.
.
.
.
</package>
Using Perl
, I have to delete all the line
nodes for which no="1"
. I have found that splice
can be used to delete nodes in xml. I have written the following code to do that:-
my $xmlFilePath = 'package.xml';
use XML::Simple;
my $xs = XML::Simple->new (ForceArray => 1);
my $ref = $xs->XMLin($xmlFilePath);
foreach(@{$ref->{'package'}}) {
my %packageTag = %{$_};
foreach(@{$packageTag{'sourcefile'}}){
my %sourcefileTag = %{$_};
my $lineCtr = 0;
foreach(@{$sourcefileTag{'line'}}){
my %lineTag = %{$_};
if($lineTag{'no'}==1){
#splice : something like "splice @{$ref{$packageTag{$sourcefileTag->{'line'}}}}, $lineCtr, 1;"
}
$lineCtr = $lineCtr + 1;
}
}
}
I am a newbie and very confused about @, %, $ conversion in Perl. I do not know how to write the array part (first argument) of the splice function. Can anyone please tell me what would be the splice function which would do the deletion of the line node?
Thanks in advance.