in reply to Updating arrays within hashes
Though this isn't your actual problem (and we're actually not given enough of a snippet to see your problem), there is an efficiency issue that can be improved upon. If @prevarray changes infrequently, why not turn it into the keys of a hash, so that you can do hash lookups instead of grep?
Your code snippet doesn't show where @prevarray comes from, but it's safe to assume based on your snippet that it's generated before your foreach loop. Since you are grepping once for each loop iteration, storing @prevarray as hash keys would eliminate the "loop within a loop" that a grep within a foreach loop creates.
As for your question; there's no way that the logic you've shown in your snippet (your if(){}else{} statement) could produce the results you're describing unless there's a problem with your references. I think it's more likely that your snippet isn't an exact cut-and-paste of the code that's giving you trouble.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Updating arrays within hashes
by jonnyw83 (Initiate) on Feb 10, 2011 at 12:20 UTC |