0

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.

1 Answer 1

4

You have {key} where you mean {$key} (twice).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.