bingohighway has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to check the existence of variables that are listed in a string e.g:
So I have a variable in existence, it may or may not have a value. I also have two strings with the name of variables in. I'd like to check to see if these variables exist but I just can't get the syntax right.$var2 = 1; # may just be $var $one = '$var'; $two = '$var2'; if(defined(the variable listed in $one)){ print "I don't want to see this\n" }; if(defined(the variable listed in $two)){ print "I want to see this" };
The strings are in the above format and I could change them, I could also use hashes, but I am wondering if there is a oneline that would just sort it out for me.
Cheers!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using a sting with a variable name
by ikegami (Patriarch) on May 11, 2009 at 14:42 UTC | |
by bingohighway (Acolyte) on May 11, 2009 at 14:47 UTC | |
by ikegami (Patriarch) on May 11, 2009 at 14:56 UTC | |
by John M. Dlugosz (Monsignor) on May 11, 2009 at 16:42 UTC | |
by ikegami (Patriarch) on May 11, 2009 at 17:15 UTC | |
by bangers (Pilgrim) on May 11, 2009 at 15:02 UTC | |
by ikegami (Patriarch) on May 11, 2009 at 15:05 UTC | |
by wol (Hermit) on May 11, 2009 at 17:28 UTC | |
by bingohighway (Acolyte) on May 12, 2009 at 08:37 UTC | |
|
Re: Using a sting with a variable name
by JavaFan (Canon) on May 11, 2009 at 14:59 UTC | |
by almut (Canon) on May 11, 2009 at 15:09 UTC | |
by ikegami (Patriarch) on May 11, 2009 at 15:02 UTC | |
by JavaFan (Canon) on May 11, 2009 at 15:04 UTC | |
by ikegami (Patriarch) on May 11, 2009 at 15:10 UTC | |
by JavaFan (Canon) on May 11, 2009 at 15:21 UTC | |
|