On Jan 15, Bart Lateur said:

>On Tue, 15 Jan 2002 00:02:55 -0500, Michael G Schwern wrote:
>
>>> If we like it -w clean: "length $3" will generate a warning if the
>>> optional part isn't present, because then, $3 will be undefined. Thus:
>>> testing defined($3) looks to be a better test, to me.
>>
>>length $3 doesn't throw a warning for some reason.  $3 is probably ''
>>when the optional part doesn't match.
>
>No it's not. Try using $3 itself as as string, instead of something
>depending on length($3), and you *will* get a warning. Besides, if $3
>was defined, my version wouldn't work.
>
>It's odd. length($s) commonly produces a warning if $s isn't defined.

It's not "odd", so much as not documented.  $<digts> are magical
variables, and as such, their "length" magic is supported by
mg.c:Perl_magic_len().  This function returns 0 for things with no length,
without raising an initialized value warning.  Peruse the source, see for
yourself.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.

Reply via email to