in reply to ||= in Hash Slice

I'm not aware of a convenient per-item combination. I hear that Perl 6 will have "hyper-operators" for that, when it reaches a stable release version >= 1.0.

I'd do that with a map, as I always use map when transforming one list into another:

@{$audit}{@$copy_fields} = map { defined $item->{$_} ? $item->{$_} : ' +' } @$copy_fields;

Your code will happily replace a value of "0" by "", and I guess that's not intended.

Replies are listed 'Best First'.
Re^2: ||= in Hash Slice
by Brovnik (Hermit) on Jan 06, 2009 at 12:15 UTC
    Yup, I guess that works, but I was hoping for something a bit more elegant.
    @{$audit}{@$copy_fields} = map { $item->{$_} || '' } @$copy_fields;
    Is probably the nearest I'll get.
    P.S. The '' vs. 0 difference is irrelevant here in my case, I just want avoid undefs.
      That may not, probably won't, work in all cases ... consider when the value of $item->{$_} is 0: in this case, the wanted value of 0 will be overwritten by the empty string, since $item->{$_} is, from a perl POV, false. Hence Corions suggestion, tho' not quite what you were seeking, is better.

      A user level that continues to overstate my experience :-))