Re: lc() with undefined arg



Tassilo v. Parseval wrote:
> 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.

I was starting to believe it might be a bug but string operators
(at least the ones below) behave like the string function 'uc'
as well:

# neither emit a warning
perl -wle 'my $foo;print $foo .""'
perl -wle 'my $foo;print $foo x 3'


--
Charles DeRykus

.



Relevant Pages

  • Re: Function Warning - Null Reference
    ... Warning 1 Function 'Dec2hms' doesn't return a value on all code paths. ... These include String, Integer, DateTime and Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: [EGN] Variable hoisting
    ... Re: The Data Quality Act ... In the process I found a SERIOUS bug in the C code. ... CS> The allocated string has no room for the trailing nul. ... An mature adult programmer would have taken it for what ...
    (comp.programming)
  • Re: Comment on trim string function please
    ... I think you have a bug. ... but does it fly past the terminating null character? ... initial space scan) then this writes outside the string. ... ASIDE FROM THE CAST "ISSUES", ...
    (comp.lang.c)
  • Re: Function Warning - Null Reference
    ... Warning 1 Function 'Dec2hms' doesn't return a value on all code paths. ... null reference exception could occur at run time when the result is used. ... default value for a String is String.Empty, the default value for an Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Visual Studio 2005 - Warning in the Error List Window
    ... I'm receiving the same warning, and although this has been brought up ... Public sBillingAddress1 As String ... Private Sub LoadAddress() ... Dim Address As New addressEntry ...
    (microsoft.public.dotnet.languages.vb)