iaw4 has asked for the wisdom of the Perl Monks concerning the following question:
now, the below code fragment works, except when a variable is not defined. so how do I handle undefined variables?
(I could turn the warning off, but then I lose the flexibility of writing something that describes the undefined variable.) /iawuse warnings FATAL => qw{ uninitialized }; my $abc = "ABC"; my $def = "DEF"; ## no $ghi is defined. my $funnystring= ' hello $abc and $def and $ghi'; $funnystring =~ s/(\$\w+)/"defined($1) ? $1 : 'unknown $1'"/gee; print $funnystring;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: super-simple regex-based template eval --- handling undefined substitutions
by Kenosis (Priest) on Sep 15, 2012 at 22:02 UTC | |
by iaw4 (Monk) on Sep 15, 2012 at 22:40 UTC | |
by Kenosis (Priest) on Sep 15, 2012 at 22:50 UTC | |
|
Re: super-simple regex-based template eval --- handling undefined substitutions
by AnomalousMonk (Archbishop) on Sep 15, 2012 at 22:05 UTC | |
by iaw4 (Monk) on Sep 15, 2012 at 22:43 UTC |