Re: why warn on undefined $1?
- From: "comp.llang.perl.moderated" <ced@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Aug 2007 19:42:23 -0700
On Aug 29, 1:49 pm, "i...@xxxxxxxxxxx" <i...@xxxxxxxxxxx> wrote:
Consider:
# colors -> colours
$token = 'colors';
$token =~ s/or(ed|ing|s)?$/our$1/;
But if $token == 'color', Perl emits a warning: Use of uninitialized
value in concatenation (.) or string. True enough, $1 is undefined,
but why bother warning? I mean, my regexp has a '?' in it because I
expect that sometimes 'color' will not have an ending.
I suspect that the answer is "it's simpler to just warn whenever an
undefined variable occurs in a string, and it's just not worth it to
detect the case when such a warning is vacuous. Try 'no warnings'.' I
can deal with that.
You could add an empty alternative to cause
$1 to match an empty string thus preventing
a warning:
$token =~ s/or(ed|ing|s|)?$/our$1/;
--
Charles DeRykus
.
- References:
- why warn on undefined $1?
- From: ihok@xxxxxxxxxxx
- why warn on undefined $1?
- Prev by Date: Re: Mac: Perl script that will run when double-clicked
- Next by Date: Sending a pdf file with perl
- Previous by thread: Re: why warn on undefined $1?
- Next by thread: win32::sqlserver not able to sql_insert
- Index(es):
Relevant Pages
|