I'll take a stab at it,
That does what you wanted at the cost of another hash.my %Control = ( ConfigData => \%ConfigData, DicomDestinations => \%DestinationData ); for my $set (qw/ConfigData DicomDestinations/) { $Data->Sql ("SELECT * FROM $set"); while ($Data->FetchRow ()) { my %x = $Data->DataHash(); $Control{$set}{$x{ID}}{$x{DataName}}= $x{DataValue}; } }
Is it worth it? That depends on how likely it is that the two operations will diverge in the future.
Added: Another way, probably better,
I wrote that as an additional method wedged into $Data's class. It would be more careful to subclass that if possible. I did not wish to create a closure on $Data.sub DataClass::doit { my ($self, $set, $hash) = @_; $self->Sql ("SELECT * FROM $set"); while ($self->FetchRow ()) { my %x = $self->DataHash(); $hash->{$x{ID}}{$x{DataName}}= $x{DataValue}; } 1; } $Data->doit('ConfigData',\%ConfigData); $Data->doit('DicomDestinations', \%DestinationData);
After Compline,
Zaxo
In reply to Re: reuse worth it for small items?
by Zaxo
in thread reuse worth it for small items?
by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |