用perl表示的結構體數組

 

有如下的從ELF文件中提取的符號信息,該如何存到perl的結構的數組中呢

00000100 T muxISR
0003f334 T AddFloat
000264a4 T addInt

 

0000a0f4 D testFloat1
0000a0f8 D testFloat2
0000a0ec D testVar1
0000a0f0 D testVar2
0000a0f0 B intCounter
00002164 T writeReg
000021a8 T writeReg16

open(my $nm,"<","nmppc.c") or die "Couldn't open file nmppc.c file for read, $!";

$str='';
my @nameList;
my $nameListSize;
my $recordCnt=0;
my $dataReordCnt=0;

my %record=('addr',5,'type','T','name',"testVar1x");
my %record2=('addr'=>5,'name'=>"testVar1x");

%MulHash=(
    'fruit'=>{'apple'=>1,'banana'=>2},
    'vegetable'=>{'potato'=>1},
    'family'=>['wife','husband','son']);
    
print("\$record{'addr'}=$record{'addr'},\$record{'name'}=$record{'name'}");
print("\$record2{'addr'}=$record2{'addr'},\$record2{'name'}=$record2{'name'}\n");
while(!eof($nm))
{
    $str=readline($nm);
    ($record{'addr'},$record{'type'},$record{'name'})=split(/ /,$str);
    
    @testArray = split(/ /,$str);  #character array
    $testStr2=join('',@testArray);
    print("$testStr2\n");
    
    if($record{'type'} eq 'D' or $record{'type'} eq 'd') # string compare use eq,ne but integer compare use ==,!=
    {
        $dataReordCnt++;
        push (@nameList,\%record);   #construct hash array
        unshift(@nameList,\%record);
        #print("\$record{'addr'}=$record{'addr'},\$record{'name'}=$record{'name'},\$record{'type'}=$record{'type'}");
    }
    $recordCnt++;
    #print($str);
}
$nameListSize=@nameList;
print("\n\$recordCnt=$recordCnt,\$dataReordCnt=$dataReordCnt,\@nameList size is $nameListSize\n");

foreach $a (@nameList)
{
    print("$a\n");
}

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章