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

Re^2: How would you rewrite this?

by ihb (Deacon)
on Apr 27, 2005 at 01:37 UTC ( [id://451821] : note . print w/replies, xml ) Need Help??


in reply to Re: How would you rewrite this?
in thread How would you rewrite this?

Note that your code doesn't follow the original with regard to the index. You only increase the index if the if branch is evaluated. You need to increase $i outside the if. I'd probably rewrite it to this though:

my @fields = qw/ ... /; for (0 .. $#fields) { get_updates($objects[$_], $fields[$_], $result_ref->{$fields[$_]} if defined $result_ref->{$fields[$_]}; }
A structure like that doesn't invite to get things out of sync.

ihb

See perltoc if you don't know which perldoc to read!