in reply to Re^4: uninitialized value in join or string
in thread uninitialized value in join or string

@values = map { defined $_ ? $_ : '' } @values;
Update: don't use map for transforming something into itself. If you're getting from a different source, though, this would be an appropriate technique.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^6: uninitialized value in join or string
by Win (Novice) on Oct 31, 2005 at 17:05 UTC
    This looks great. However, I would be very pleased if somebody could describe it in English. ;>
      map acts like a foreach loop, walking through an array (or list) and aliasing $_ to each element in turn. In addition to walking the list, though, map also constructs an array. The upshot is that you can transform an array with it.

      But explaining that just made me realize that you can get the same result with a foreach loop in this case:

      foreach (@values) { $_ = '' unless defined; }
      That should be more clear. It updates each undefined element of @values to be the empty string.

      Caution: Contents may have been coded under pressure.