Re: lc() with undefined arg



Also sprach Stephen Hildrey:

> Len@xxxxxxxxxxxx wrote:
>> Is it documented that lc() doesn't mind an undefined argument ?
>
> I can't see it documented, but it is a common idiom when using CGI.pm to
> use:
>
> my $foo = lc(param('foo'));
>
> for exactly the purpose you describe - supressing the undef warnings.
>
> I am not a Perl internals hacker, but at a guess (and I am probably
> wrong) this source looks relevant:
>
> if (!len) {
> SvUTF8_off(TARG); /* decontaminate */
> sv_setpvn(TARG, "", 0);
> SETs(TARG);
> }
>
> (perl 5.8.6 - pp.c lines 3587 - 3591)

It's not really surprising that this behaviour is implemented somewhere
in the source. However, the code you quote is common in string handling
routines that usually upgrade undef to the empty string. The actual
check for emitting the warning normally happens before. But not in the
case of (uc|lc)(_first)? and possibly others for no apparent reason.

I'm inclined to say this is a bug unless someone is able to explain the
reasoning behind that behaviour.

Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
.