my @products = (
{"value"=> "apple", "mount"=>"1"},
{"value"=> "bag", "mount"=>"2"},
{"value"=> "car", "mount"=>"3"}
);
移除value为bag的hash,返回新的数组
my @newproducts = (
{"value"=> "apple", "mount"=>"1"},
{"value"=> "car", "mount"=>"3"}
);
#! /usr/bin/perl -w
use Data::Dumper;
my @products = (
{"value"=> "apple", "mount"=>"1"},
{"value"=> "bag", "mount"=>"2"},
{"value"=> "car", "mount"=>"3"}
);
my @newproducts = ();
foreach my $tmp (@products) {
next if (grep (/^bag$/,values %{$tmp}));
push @newproducts,$tmp;
}
print Dumper(\@products);
print Dumper(\@newproducts);
亲测可用