in reply to If condition
Can you please tell me what is the problem in above conditions.
Hard to be sure without knowing more about your data. What unexpected behaviour are you seeing? Do you really have hashes with keys called "key" and "value"?
How to store the value of $cor and $date oustide the if condition
Store the values in variables that are declared outside of the if block.