Reputation: 23502
I want to remove values which contain "local" string in their value. here is my hash output (print Dumper ($hash)
):
$VAR1 = {
'FARM_03' => [
'nfs01',
'nfs02',
'nfs03',
'localvmfs',
'localvmfs'
],
'FARM_07' => [
'nfs01',
'localvmfs',
'localvmfs'
],
'FARM_11' => [
'nfs01',
'localvmfs',
'localvmfs'
]
};
Hence I wrote below code in my script to omit the "local" entries:
foreach my $key ( keys %$hash )
{
@{ $hash->{key} } = grep { !/local/i } @{ $hash->{key} };
}
and here is the output after running above grep command:
$VAR1 = {
'FARM_03' => [
'nfs01',
'nfs02',
'nfs03',
'localvmfs',
'localvmfs'
],
'FARM_07' => [
'nfs01',
'localvmfs',
'localvmfs'
],
'FARM_11' => [
'nfs01',
'localvmfs',
'localvmfs'
]
'key' => []
};
It is not removing the "local" entries as well as it adds a new field 'key' => []
.
Could you tell me what is wrong with my grep statement.
Thanks.
Upvotes: 0
Views: 899