Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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 "; } } }

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 fire pops...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-01-22 12:47 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (233 votes). Check out past polls.