I need help to write a perl script for printing out the initial values of the bit fields of a register as a 8 bit value. The information available in the file is like
<reg>
...
<bit id= 7>
<name>A</name>
<init_val>1</init_val>
</bit>
<bit id= 6>
<name>B</name>
<init_val>0<init_val>
</bit>
...likewise bits upto 0
</reg>
Likewise the file contains of 100 regs. I want to print out the 'init_val' of all the bit fields of the registers.
I have tried writing the script
while($line=<IN>)
{
....
#reg bit field
if($line=~/\<bit\sid\=\"(.*)\"\>/)
{
$bit_name=$1;
...
print "Line no. where the bit field has been found : $.\n\n";
#As 'init_val' occurs on the second line after 'bit id'
$line_count=$.+2;
print "The incremented value is $line_count\n\n ";
#reading the initial_value
print "####################\n\n\n";
while($sub_line=<IN>)
{
print "**********************Entered the second loop******
+************\n\n\n";
print "The line no is $.\n\n";
if($.==$line_count)
{
if($sub_line=~/\<INIT\_VAL\>(.*)\<\/INIT_VAL\>/)
{
$bits{"$bit_name"}=$1;
print "...................The bit field initial value
+is $1......... \n\n"
}
if($sub_line=~/\<INIT\_VAL\/\>/)
{
$bits{"$bit_name"}=0;
print "The bit field initial value is 0\n\n\n "
}
}
print "End of the Loop\n\n";
%bits=qw(0 0);
}
print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n";
$.=$line_count;
print "THE LINE COUNT IS $.\n\n ";
}
...
}
But the above code is not working properly. After the first bit field,it is getting exited. It is not going to other bit fields of the reg as well as not other registers in the file