I want to do some hash slice assigns.
my $key_fields = [ qw( trade_ref sec_code lot of other fields ) ];
my $copy_fields = [ qw( item_period other fields) ];
my $audit = {};
@{$audit}{@$key_fields} = @{$item}{@$key_fields};
# $item is a hashref with some but maybe not all of the
# above fields defined
$audit->{$_} = $item->{$_} || '' for @$copy_fields;
Alternatively :
@{$audit}{@$copy_fields} = @{$item}{@$copy_fields};
$audit->{$_} ||= '' for @$copy_fields;
These work, but I really want to do :
@{$audit}{@$copy_fields} = @{$item}{@$copy_fields} || '';
to make sure there are no undefs. Can I do the above as a single Hash slice assignment ?