Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: Compare Two Hash refs of Hashes

by kalyanrajsista (Scribe)
on Jul 16, 2010 at 16:57 UTC ( #850003=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Compare Two Hash refs of Hashes
in thread Compare Two Hash refs of Hashes

Thanks for your efforts

I want to check only particular fields like sdrpretax_vcd taxamt_vcd sdrposttax_vcd dchdetaildate in $old and $new hashes. If there are any differences, I must update the values from $new hash. Please let me know if I can achieve in minimal steps rather than looping around the hashes...

foreach my $TAP ( keys %{$new} ) { ; if ( exists($old->{$TAP}) ) { ; my $hasUpdated = '0'; foreach my $check_field ( qw(sdrpretax_vcd taxamt_vcd sdrpostt +ax_vcd dchdetaildate) ) { ; if ( $new->{$TAP}->{$check_field} ne $old->{$TAP}->{$check +_field} ) { ; $hasUpdated = 1; last; } } if ( $hasUpdated ) { print " Has to update the DB now "; } } }


Comment on Re^4: Compare Two Hash refs of Hashes
Download Code
Re^5: Compare Two Hash refs of Hashes
by jethro (Monsignor) on Jul 16, 2010 at 23:39 UTC
    Why are your requirements changing all the time? Maybe you want this:
    if ( exists $new->{$TAP}->{$check_field} and (not exists $old->{$TAP}->{$check_field} or $new->{$TAP}->{$che +ck_field} ne $old->{$TAP}->{$check_field}) ) { $hasUpdated = 1; last; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-12-26 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (164 votes), past polls