-2

Can I search variable name as a regex in perl? and not its value. something like below algo

$var = 0;
$pattern = "abc";

if($i = var)   #here I want to check if "pattern" is "var" or not. and dont want to compare actual values of them like "0" and "abc".
then
    do something
endif

Can anybody please help?

Joseph Idziorek
  • 4,853
  • 6
  • 23
  • 37
Anu
  • 9
  • 1
  • What language are you using? – Tim Biegeleisen Aug 11 '15 at 04:27
  • I dont understand what stops you from using the name of the variable if you know it beforehand. If you dont know the variable names, there are several ways to get it http://www.perlmonks.org/?node_id=1002907 http://stackoverflow.com/questions/747521/how-can-i-list-all-variables-that-are-in-a-given-scope http://stackoverflow.com/questions/735386/what-s-the-best-way-to-discover-all-variables-a-perl-application-has-currently-d – SAN Aug 11 '15 at 05:01
  • It is an existing code. and a single function is being used which will behave differently for same condition execution. – Anu Aug 11 '15 at 05:33
  • Then come up with a short example where you would use this so we can understand what you are really asking. As it stands, if I am typing `$var` in the editor, I know what pattern the name of that variable matches before `perl` runs. Why do I need a regex match to figure it our? – Sinan Ünür Aug 11 '15 at 10:30

1 Answers1

1

Whenever you find yourself wanting to perform string comparisons on variable names, think "I should have used a hash".

See also How can I use a variable as a variable name in Perl?.

Community
  • 1
  • 1
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339