- 论坛徽章:
- 0
|
if(-e $CONFIG_DIR."/".$CONFIG_NAME){
print "read $CONFIG_NAME\n";
my @records = read_config_file($CONFIG_DIR."/".$CONFIG_NAME); # read_config_file的功能是返回一个散列数组,其中所有数据都在这个数组中了
print "print records\n";
for my $href (@records){
print "{";
for my $role ( keys %$href ){
print "$role = $href->{$role} ";
}
print "}\n";
}
for my $href (@records){
for my $role (keys %$href){
if($role eq "OPTIONS" && $href->{$role} eq "ADD"){
print "OK, i will do ADD action\n";
}
}
}
sub read_config_file {
my @hash_array;
my $fl = shift;
my ($volume,$path,$file) = File::Spec->splitpath( $fl );
chdir $path or die "can not change dir to $path\n";
open(FH,"<",$file) or die "can not open file\n";
my %ha;
while(<FH>){
next if m/^#/; # next if comment
if(m/^$/){ # next if nothing ,and push %ha if have key in it
if(keys %ha){
push @hash_array,{%ha};
}
next;
}
my ($key ,$value) = split /\s:\s/;
$ha{$key} = $value;
}
close(FH);
return @hash_array;
}
[ 本帖最后由 justlooks 于 2009-11-3 16:26 编辑 ] |
|