in reply to (jeffa) Re: Sorting data pullled in by DBI
in thread Sorting data pulled in by DBI

My favorite idiom for defaulting a set of values is:
# psuedocode $_ = DEFAULT for grep !CONDITION, @VALUES; # as it applies in this situation $_ = ' ' for grep !$_, @row;

-Blake

Replies are listed 'Best First'.
Re: Re2: Sorting data pullled in by DBI
by Kanji (Parson) on Mar 18, 2002 at 02:57 UTC

    The problem with !$_ (and jeffa's map example), is that it tests for truth, so you also end up substituting any values that match 0 instead of only those that are undef.

    Perhaps you meant to use !defined instead?

        --k.


      Yes, !defined is probably a better CONDITON for the original data... I was merely refactoring the given map code. However, since you probably want the empty string to be defaulted as well, I'd probably use something like:
      $_ = ' ' for grep {!defined or $_ eq ''} @arr;

      -Blake