in reply to Re: Remove similar key=value pair from HOH
in thread Remove similar key=value pair from HOH

Hmm, not convinced.
$ perl -e 'use Data::Dumper; > > my %hash =( > 'script' => 'foo.pm', > 'params' => { > 'err' => '99', > 'FILE' => 'fileA' > }, > 'par_global' => { > 'err' => '99', # this value (99) is + overwritten > 'err' => '20', # with (20) > 'FILE_READ' => 'fileB', > }, > 'testset' => ['test1'] > ); > > print Dumper( \%hash ) . "\n";' $VAR1 = { 'params' => { 'FILE' => 'fileA', 'err' => 99 }, 'script' => 'foopm', 'par_global' => { 'FILE_READ' => 'fileB', 'err' => 20 }, 'testset' => [ 'test1' ] };

Je suis Charlie.

Replies are listed 'Best First'.
Re^3: Remove similar key=value pair from HOH
by LanX (Saint) on Apr 12, 2015 at 00:09 UTC
      What's the problem?

      The expression  'script' => 'foo.pm' is rendered in the  Dumper output as "'script' => 'foopm'", which is puzzling (although I cannot reproduce this ;-)


      Give a man a fish:  <%-(-(-(-<

        Quoting issue. Single quotes can't be nested, so foo and pm are unquoted, i.e. interpreted as barewords, and as no such functions exist, they're turned into strings and concatenated by the dot operator.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      bash-4.2$ cat dump use Data::Dumper; my %hash =( 'script' => 'foo.pm', 'params' => { 'err' => '99', 'FILE' => 'fileA' }, 'par_global' => { 'err' => '99', 'FILE_READ' => 'fileB', }, 'testset' => ['test1'] ); print Dumper( \%hash ) . "\n";
      bash-4.2$ perl dump $VAR1 = { 'params' => { 'FILE' => 'fileA', 'err' => '99' }, 'script' => 'foo.pm', 'par_global' => { 'FILE_READ' => 'fileB', 'err' => '99' }, 'testset' => [ 'test1' ] };

      My question is while traversing the hash if'err' => '99' is mentioned again, it should just avoid it.

        ... if'err' => '99' is mentioned again ... just avoid it.

        Do you mean "If the key 'err' is mentioned again with the specific value of '99', avoid it", or "If the key 'err' is mentioned again with any value, avoid it"?


        Give a man a fish:  <%-(-(-(-<

        My question is while traversing the hash if'err' => '99' is mentioned again, it should just avoid it.
        No, because they are in different "sub-hashes". The first "err" key-value pair is in the hash referenced by 'params', while the second one is in the hash referenced by 'par_global'. Two different hashes.

        Je suis Charlie.