in reply to reuse worth it for small items?

It is certainly possible to golf this down, and it is an interesting exercise, but in practice it's unlikely to make the code more legible or reusable, so for production purposes I would not recommend it.

As far as how to golf it down, my first thought would be to reach for map update: like the following...

map{$Data->Sql("SELECT * FROM $_"); while($x=$Data->fetchrow_hashref){ $ConfigData{$$x{ID}}{$$x{DataName}}=$$x{DataValue}}; }qw(ConfigData DicomDestinations);

I'm sure someone can shave some more strokes off that.


Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. Why, I've got so much sanity it's driving me crazy.

Replies are listed 'Best First'.
Re^2: reuse worth it for small items?
by revdiablo (Prior) on May 05, 2006 at 22:10 UTC

    The map doesn't buy you much in terms of golf here, and he's also changing the target hash. I'd probably approach it something more like:

    my @table_to_hash = ( [ "ConfigData", \%ConfigData ], [ "DicomDestinations", \%DestinationData ] ); for (@table_to_hash) { my ($table, $hash) = @$_; $Data->Sql("SELECT * FROM $table"); while ($Data->FetchRow ()) { my %x = $Data->DataHash(); $hash->{ $x{ID} }{ $x{DataName} } = $x{DataValue}; } }

    Update: I see this is almost the same as Zaxo's post at Re: reuse worth it for small items?, but note that mine will maintain the order. I'm not sure it matters, but it could.