Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Remove similar key=value pair from HOH

by pme (Monsignor)
on Apr 11, 2015 at 19:33 UTC ( [id://1123147]=note: print w/replies, xml ) Need Help??


in reply to Remove similar key=value pair from HOH

Hi vaibhav07,

Perl hash unable to store duplicated keys. See and run the code snippet below.

use Data::Dumper; my %hash =( 'script' => 'foo.pm', 'params' => { 'err' => '99', 'FILE' => 'fileA' }, 'par_global' => { 'err' => '99', # this value (99) is o +verwritten 'err' => '20', # with (20) 'FILE_READ' => 'fileB', }, 'testset' => ['test1'] ); print Dumper( \%hash ) . "\n";

Replies are listed 'Best First'.
Re^2: Remove similar key=value pair from HOH
by Laurent_R (Canon) on Apr 11, 2015 at 22:46 UTC
    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.
        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:  <%-(-(-(-<

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1123147]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-23 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found