in reply to Re: find and replace project with values coming from a table
in thread find and replace project with values coming from a table

Just one nit:
If the replacement value is not true, it fails to replace.

I recommend replacing

$_ = $subs {$_} || $_;
with
$_ = exists $subs {$_} ? $subs {$_} : $_;
so that a 0 could also be used as a replacement value.

Although I must say, it does somewhat damage the visual aesthetics.
--
Snazzy tagline here

Replies are listed 'Best First'.
Re: find and replace project with values coming from a table
by Abigail-II (Bishop) on Jul 05, 2003 at 11:39 UTC
    I choose for the former because with the given data, the problem doesn't arise. If you want to be able to cope with possible false values (except for 0, the empty string, and undef would be false too) I would use:
    $_ = $subs {$_} if exists $subs {$_};

    The effect is the same of course, but it looks better IMO.

    Abigail

      Agreed, that does look a lot better! It's technically better too, as mine was foolishly replacing $_ with itself in the event of a failed match.
      --
      Snazzy tagline here