http://qs1969.pair.com?node_id=498380


in reply to Handling MS-Access date time

Too little detail in one respect: I don't know what different behavior you'd like to see. But here's a way to transform a field while keeping the inside of your loop nice and field-agnostic -- I'll guess that you want to strip the time and display just the date.

use Data::Dumper; my %field_filter = (creation_date => sub { my $datetime = shift; retur +n (split ' ', $datetime)[0] } ); my @fields = (qw(creation_date a b)); my @hash_ops = ({a => '', b => 2, creation_date => '12/31/2005 12:32:1 +1'}, {a => 5, b => 0, creation_date => '23/01/2222 13:14:15'}); my @loop_data; for my $hash_op (@hash_ops) { my %row_data; foreach my $field (@fields) { if ($hash_op->{$field}) { $row_data{$field} = exists $field_filter{$field} ? $field_filter +{$field}->($hash_op->{$field}) : $hash_op->{$field}; } else { $row_data{$field} = '-'; } } push (@loop_data, \%row_data); } print Dumper(\@loop_data)

This outputs:

$VAR1 = [ { 'a' => '-', 'creation_date' => '12/31/2005', 'b' => 2 }, { 'a' => 5, 'creation_date' => '23/01/2222', 'b' => '-' } ];