perl-unicode

RE: Encode should stay undefphobia

2002-04-30 15:05:40
From: Dan Kogai [mailto:dankogai(_at_)dan(_dot_)co(_dot_)jp]

On Wednesday, May 1, 2002, at 02:10 , Nick Ing-Simmons wrote:
Dan Kogai <dankogai(_at_)dan(_dot_)co(_dot_)jp> writes:

Please don't.

$a =~ tr/A/a/;

gives a warning so should encode/decode.

How can I be so dumb for not anticipating you say that! (Blame it on the
fever).  Paul, I  now think Nick's got more points than yours so I will
revert it in the next version.  Maybe I will document this undef-phobia
of Encode subs in the POD....

Good catch Nick.

Instead of completely backing out the "defined $str or return" change, if
you change it to

   unless (defined $str) {
     warnif('uninitialized', 'Use of Uninitialized value in encode_utf8');
     return;
   }

that gives us the same warning behaviour as print/tr/etc, but more
importantly it also gives users of the module the ability to silence the
uninitalized warning in the same way they do with print/tr, thus:

  use warnings;
  ...
  {
    no warnings 'uninitialized';
    Encode::encode_utf8($x);
  }

Paul

<Prev in Thread] Current Thread [Next in Thread>