in reply to detecting an undefined variable
UPDATE: I took it as a challenge to do what you asked for using strict vars with eval.
use warnings; use Test::Simple tests => 3; # Test wether or not the target of a symbolic reference is declared. my $xxx ; our $yyy; { use strict vars; my $sym_ref; $sym_ref = '$xxx'; ok ( do{eval $sym_ref; !$@}, 'declared lexical'); $sym_ref = '$yyy'; ok ( do{eval $sym_ref; !$@}, 'declared package'); $sym_ref = '$zzz'; ok (!do{eval $sym_ref; !$@}, 'not declared'); # Note: !do..... }
This test does what you wanted, but not what you need because symbolic-refs only work with package variables. Of course once you know that the variable is declared, you could use LanX's idea and check if the name 'exists' in the symbol table. Even that could fail in special cases. DO NOT USE SYMBOLIC REFERENCE!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: detecting an undefined variable
by LanX (Saint) on Sep 21, 2019 at 16:28 UTC | |
by Haarg (Priest) on Sep 21, 2019 at 20:45 UTC | |
by LanX (Saint) on Sep 21, 2019 at 21:20 UTC | |
by LloydRice (Beadle) on Sep 21, 2019 at 16:50 UTC | |
by LanX (Saint) on Sep 21, 2019 at 17:02 UTC | |
by LloydRice (Beadle) on Sep 21, 2019 at 17:48 UTC | |
by AnomalousMonk (Archbishop) on Sep 21, 2019 at 20:25 UTC |