Brovnik has asked for the wisdom of the Perl Monks concerning the following question:
Alternatively :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;
These work, but I really want to do :@{$audit}{@$copy_fields} = @{$item}{@$copy_fields}; $audit->{$_} ||= '' for @$copy_fields;
to make sure there are no undefs. Can I do the above as a single Hash slice assignment ?@{$audit}{@$copy_fields} = @{$item}{@$copy_fields} || '';
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: ||= in Hash Slice
by ikegami (Patriarch) on Jan 06, 2009 at 12:40 UTC | |
Re: ||= in Hash Slice
by Corion (Patriarch) on Jan 06, 2009 at 12:00 UTC | |
by Brovnik (Hermit) on Jan 06, 2009 at 12:15 UTC | |
by Bloodnok (Vicar) on Jan 06, 2009 at 17:56 UTC | |
Re: ||= in Hash Slice
by gone2015 (Deacon) on Jan 06, 2009 at 12:08 UTC | |
by Brovnik (Hermit) on Jan 06, 2009 at 12:12 UTC | |
by ikegami (Patriarch) on Jan 06, 2009 at 12:31 UTC | |
Re: ||= in Hash Slice
by JavaFan (Canon) on Jan 06, 2009 at 12:33 UTC |