kiat has asked for the wisdom of the Perl Monks concerning the following question:
I've a contrived regex below that triggers "Use of uninitialised value in concatenation ..." warning.
When both $1 and $2 are initialised (i.e. $1 matched to the digit 6 and $2 to the word after, no warning is triggered. But with the 6 gone, $1 becomes uninitialised and so the "Use of uninitialised value in..." warning is triggered.use strict; use warnings; use diagnostics; my $str = "6%var% after"; # $str = "%var% after"; <-- warning is triggered $str =~ s/(\d)?%var%(.*)/$1REPLACED$2/; print "$str\n"
How do I fix that?
Thanks in anticipation :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex triggering uninitialised values
by ikegami (Patriarch) on Nov 19, 2004 at 17:39 UTC | |
by kiat (Vicar) on Nov 19, 2004 at 17:49 UTC | |
by Eimi Metamorphoumai (Deacon) on Nov 19, 2004 at 18:01 UTC | |
by kiat (Vicar) on Nov 19, 2004 at 18:06 UTC | |
|
Re: Regex triggering uninitialised values
by jimbojones (Friar) on Nov 19, 2004 at 17:36 UTC | |
by kiat (Vicar) on Nov 19, 2004 at 17:46 UTC | |
by Eimi Metamorphoumai (Deacon) on Nov 19, 2004 at 17:58 UTC | |
by ysth (Canon) on Nov 19, 2004 at 17:50 UTC | |
|
Re: Regex triggering uninitialised values
by Kyoichi (Novice) on Nov 20, 2004 at 20:02 UTC |