Parsing a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amittewarii
    New Member
    • Feb 2007
    • 3

    Parsing a file

    Hello Everybody ,
    I need help in parsing the given file ,

    ############### ############### ############### ############### #####
    <sample_cfg : 00FF_F000>
    #f_name bit_pos reset_val readable? writeable? special
    sample_set 31:16 0000 y y -
    sample_status 15:0 FFFF y n W1C
    </sample_cfg>


    <sample_int : 00FF_F100>
    #f_name bit_pos reset_val readable? writeable? special
    sample_set 0 0 y n W1C
    sample_status 1 0 y n W1C
    </sample_int>

    <sample_int_mas k : 00FF_F200>
    #f_name bit_pos reset_val readable? writeable? special
    sample_set 0 0 y y -
    sample_status 1 0 y y -
    </sample_int_mask >


    The data has to be extracted first and then formed in the form of a "Hash of Hash of Hash "

    <sample_cfg : some value > is the register name
    which has 2 function sample_set & sample_status . Each of this function has 5 fields . We need to parse them out and fill them in a HoHoH so that they could be represted in the form of a tree .

    Regards ,
    Amit
  • prn
    Recognized Expert Contributor
    • Apr 2007
    • 254

    #2
    Well, as far as the parsing is concerned, the obvious (i.e., off the top of my head and not tested :-) ) would be something like:

    [code=perl]...
    open SMPL, "<sample_cf g" or die "Could not open file for reading: $! \n";
    while ( <SMPL> ) {
    if ( /^sample_/ ) {
    ($f_name, $bit_pos, $reset_val, $readable, $writeable, $special ) = split;
    .... # now that the line is parsed, do whatever, e.g., put it into your HoHoH
    }
    }
    close SMPL;[/code]

    Note that the split function defaults to splitting the $_ (line just read) at spaces, which looks like exactly what you want to do.

    HTH,
    Paul

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      I see in your first thread in this forum you posted some code so I assume you will have some code written already that you have been working with. Please post that code.

      Comment

      Working...