There's two things you're trying to do. Parse a file, and insert into a hash. At a basic level, it goes like this:
use strict;
use warnings;
use Data::Dumper;
my %defines;
open ( my $input_fh, "<", "input-file-name" ) or die $!;
while ( <$input_fh> ) {
my ( $key, $value ) = ( m/^s*#s*defines+(w+)s+(w+)/ );
$defines{$key} = $value;
}
print Dumper \%defines;
That's all there is to it, really. A hash is an (unordered) set of key-value pairs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…