Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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
Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2015-09-04 11:30 GMT
Find Nodes?
    Voting Booth?

    My preferred temperature scale is:

    Results (135 votes), past polls