Updating lots of database fields in a single row

William Blunn bill+london.pm at blunn.org
Wed Jan 23 10:05:43 GMT 2013

On 23/01/2013 09:52, Mark Overmeer wrote:
> * Ruud H.G. van Tol (rvtol at isolution.nl) [130123 09:45]:
>> On 2013-01-23 10:27, William Blunn wrote:
>>> my @fields_to_update = grep { $hash->{$_} } @fields; 
>> Be aware that it skips any false value, like undef, '', '0', 0. 
> my @fields_to_update = grep defined $hash->{$_}, @fields;
> But that's is probably not true either: after the $hash was read from 
> the database, logic may have cleared some of these fields. The 
> clearing itself usually needs to be moved into the database as well... 
> undef fields need to be set to NULL. 


exists $hash->{$_}

would mean that undef values in %$hash were included, which would result 
in NULL being set in the corresponding database columns, which could be 
a useful approach for the OP.



More information about the london.pm mailing list