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

What's the problem?

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

  • Comment on Re^3: Remove similar key=value pair from HOH

Replies are listed 'Best First'.
Re^4: Remove similar key=value pair from HOH
by AnomalousMonk (Archbishop) on Apr 12, 2015 at 00:27 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.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        Ah! Looking at Re^2: Remove similar key=value pair from HOH again, I see it's run without strictures and apparently on a *nix system. Interesting. I was trying to reproduce on Windows: I guess Windows has to be good for something!


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

Re^4: Remove similar key=value pair from HOH
by vaibhav07 (Acolyte) on Apr 12, 2015 at 04:29 UTC
    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.
        No, because they are in different "sub-hashes".

        But my guess (and at this point that's all it is) about what vaibhav07 wants is some kind of custom traversal routine that will avoid some or all keys that have already been "seen", even if they were members of separate and distinct (sub-)hashes. Or something like that. Maybe. Update: As pme has suggested, a strong scent of XY Problem here.


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