dmitri has asked for the wisdom of the Perl Monks concerning the following question:
# This works fine $a = "abc"; $a =~ s/^(?:a(\w))?(\w)$/$1:$2/; # works fine # This produces the warning # "Use of uninitialized value in concatenation (.) $b = "c"; $b =~ s/^(?:a(\w))?(\w)$/$1:$2/;
I do not mind $1 to be empty; in fact, I want it to be empty if ^a\w is not there. But I only want to put the second character in $1 if the first character is "a", so
$b =~ s/^a?(\w?)(\w)$/$1:$2/; # no warning here.
won't do. The $64,000 question is, can I accomplish this in one line and not produce a warning?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Uninitialized $1 in s///
by mirod (Canon) on Jan 02, 2002 at 09:33 UTC | |
by Aristotle (Chancellor) on Jan 02, 2002 at 20:18 UTC | |
by dmitri (Priest) on Jan 02, 2002 at 20:43 UTC | |
|
Re: Uninitialized $1 in s///
by blakem (Monsignor) on Jan 13, 2002 at 14:05 UTC |