如何用perl提取一个.h文件里的数据,并将数据放到两个数组里?

如何用perl提取一个.h文件里的数据,并将数据放到两个数组里?

现在有一个文件: data.h, 其内容如下:

/*  File Name:  data.h */
UC D1[] =
    {
        //D1P
0,6,13,123,0,32,4,81,
3,109,0,23,5,17,32,12,

    };
UC D2[] =
    {
        //D2
127,107,127,132,127,127,111,127,
127,125,127,127,127,127,127,127,
    };

    现在要使用D1和D2里的数据,如何把D1和D2里的数据写到数组d1和d2里去呢? 哪位大侠能帮忙给段代码,兄弟感激不尽......
#!/usr/bin/perl

use strict;
use warnings;

my %array_hash;
my $array_name;
while (<DATA>) {
    chomp;
        $array_name = lc $1 if (/(D.)\[/);
        if (/(\d,)+/) {
                s/\s//;
                push @{$array_hash{$array_name}}, (split ',', $_);
        }}

for (keys %array_hash) {
    print "$_\n";
        print "\t$_ \n" for @{$array_hash{$_}};
}

__DATA__
/*  File Name:  data.h */
UC D1[] =
    {
        //D1P
0,6,13,123,0,32,4,81,
3,109,0,23,5,17,32,12,

    };
UC D2[] =
    {
        //D2
127,107,127,132,127,127,111,127,
127,125,127,127,127,127,127,127,
    };

我这里有一种读文件的内容的方法,不过是读变量内容,不是读数组,给你参考一下:
file content for "data.seq":

QUOTE:
$isa_no = 453
$gs_no = 453
$st_no = 1853

Code

[Copy to clipboard] [ - ]
CODE:
#!/usr/bin/perl -w
my $config_file = "data.seq";
my $isa_no = 0;
my $gs_no = 0;
my $st_no = 0;
open(CONFIGFILE, "<", $config_file) or die("Cannot open config file: $config_file.\n");
while(my $line = <CONFIGFILE>){eval($line);}
close(CONFIGFILE);
print "$isa_no\n";
print "$gs_no\n";
print "$st_no\n";

#!/usr/bin/perl
use warnings;
use strict;

my @r;
my %h;
my $flag = 0;
while(<DATA>)
{
    chomp;
    if(/\/\//)
    {
        $flag = 1;
}
    if(/}/)
    {
        $flag = 0;
    }
    push @r,$1 if /\/\/(\w+)/;
    if($flag && !($_=~/\/\/(\w+)/))
    {
        $h{$1} .= $_;
   }
}
print $h{$_},"\n" for @r;



__DATA__
/*  File Name:  data.h */
UC D1[] =
    {
        //D1P
0,6,13,123,0,32,4,81,
3,109,0,23,5,17,32,12,
    };
UC D2[] =
    {
        //D2P
127,107,127,132,127,127,111,127,
127,125,127,127,127,127,127,127,
    };