Re: Use of uninitialized value in substitution (s///)



Hugh Lawson <hlawson@xxxxxxxxxxxx> wrote in comp.lang.perl.misc:
> anno4000@xxxxxxxxxxxxxxxxxxxxxxx (Anno Siegel) writes:

[...]

> > > How can the code work right if $_ is undefined?
> >
> > Perl converts the undefined value to an empty string, if forced. It
> > does that here, finds that the empty string doesn't end with a "0" and
> > returns the empty string unchanged. That works perfectly well, but it
> > may not be what the programmer intended, hence the warning.
>
>
> Hello Anno,
>
> Thank you for the reply. Perhaps we are communicating at cross
> purposes. My point is that warning or not, the substitution seems to
> work as expected.

How is that surprising? The purpose of the substitution is to get rid
of a trailing null byte in C strings. If $_ is undefined, the
substitution returns an empty string. That doesn't have a trailing null
byte, so the purpose of the substitution is attained.

> To see what I'm talking about, search for this line
>
> $db->filter_fetch_value(
> sub { no warnings 'uninitialized' ;s/\0$// } ) ;
>
> in perldoc perldbmfilter.

I don't have perldbmfilter around (is it really spelled that way?).
The code is the same as earlier in the thread. What's to discover?

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
.



Relevant Pages

  • Re: Bizarre regex behaviour
    ... >>> regexp in the last successful match is used instead. ... >For searching rather than substitution. ... >a substitution with an empty string is always taken to mean ...
    (comp.lang.perl.misc)
  • Re: capture scoping
    ... > amongst other regexes. ... A substitution will happily substitute an empty string ... show your input data. ...
    (comp.lang.perl.misc)
  • Re: Bizarre regex behaviour
    ... >> regexp in the last successful match is used instead. ... For searching rather than substitution. ... a substitution with an empty string is always taken to mean ...
    (comp.lang.perl.misc)
  • Re: lc() with undefined arg
    ... > undef: 'reverse' in scalar context. ... the value is no longer undef but the empty string. ... "Reply" at the bottom of the article headers. ...
    (comp.lang.perl.misc)
  • .bottom of TextWidthHeight
    ... Within the With block of "sRect" ... Variable in question: ".Bottom" ... properly calculate the .Bottom variable where the rowsource of a listbox is ... Have the code arbutarily put in a string value that is not an empty string ...
    (microsoft.public.access.formscoding)