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

In reply to help to write perl code by achs

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.