Re: why warn on undefined $1?
- From: Mirco Wahab <wahab@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Aug 2007 23:13:59 +0200
ihok@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.
xhoster did already point to a solution,
but you could also be more explicit about
your search term, e.g.
my $token = 'color';
$token =~ s/ \B or(ed | ing | s | $)? /our$1/x;
by simply putting the $ (or a \b) into the
capturing parenthesis. I added another \B
in front of the term in order to make
clear that we start the search in the
middle of a word.
.
- References:
- why warn on undefined $1?
- From: ihok@xxxxxxxxxxx
- why warn on undefined $1?
- Prev by Date: Re: why warn on undefined $1?
- Next by Date: Re: why warn on undefined $1?
- Previous by thread: Re: why warn on undefined $1?
- Next by thread: Re: why warn on undefined $1?
- Index(es):
Relevant Pages
|
|