define host{ use windows-server .... } define host{ use windows-server } is ok, BUT define host{ use windows-server .... } define host{ use windows-server } is not ok! #### #!usr/bin/perl -w use strict; use Data::Dumper; my @DB; my %hash = (); while () { if ( m/^define/.../}\s*$/) { next if /{\s*$/; next if /\s*\}\s*/; my ($hkey,$hval) = split; $hash{$hkey}=$hval; } else { push @DB, {%hash}; } } push @DB,{%hash}; print Dumper \@DB; #Array of Hash has been created deleteDB ('address' => '192.168.1.1'); #delete one record sub deleteDB { my ($key,$value) = @_; @DB = grep {$_->{"$key"} ne "$value"} @DB; } print "=============================\n"; print Dumper \@DB; #Prints: #$VAR1 = [ # { # 'use' => 'windows-server', # 'hostgroups' => '060202', # 'host_name' => 'serverA', # 'address' => '192.168.1.1', # 'alias' => '060202', # 'contact_groups' => 'yu' # }, # { # 'use' => 'windows-server', # 'hostgroups' => '060202', # 'host_name' => 'serverA', # 'address' => '192.168.1.11', # 'alias' => '060202', # 'contact_groups' => 'yu' # }, # { # 'use' => 'windows-server', # 'hostgroups' => '060202', # 'host_name' => 'serverA', # 'address' => '192.168.1.21', # 'alias' => '060202', # 'contact_groups' => 'yu' # } # ]; #============================= #$VAR1 = [ # { # 'use' => 'windows-server', # 'hostgroups' => '060202', # 'host_name' => 'serverA', # 'address' => '192.168.1.11', # 'alias' => '060202', # 'contact_groups' => 'yu' # }, # { # 'use' => 'windows-server', # 'hostgroups' => '060202', # 'host_name' => 'serverA', # 'address' => '192.168.1.21', # 'alias' => '060202', # 'contact_groups' => 'yu' # } # ]; __DATA__ define host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.1 } define host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.11 } define host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.21 }