0

Is there a way in Perl to evaluate expressions in string variables ? I am using Perl 5.8 While parsing files, I came across a string like this :

var_xx = ((216<<23)|34);

I am trying to make a hash table for each variable along with its value. But in such conditions, Its not working. In my perl script I have

$str=((216<<23)|34); (String context)

Is there some function such that

$val = some_func($str);

and $val should now contain the value in $str.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Utkarsh Kumar
  • 567
  • 1
  • 5
  • 17

1 Answers1

2

eval will do what you want, but just because you can doesn't mean that you should

Zaid
  • 36,680
  • 16
  • 86
  • 155
  • 2
    @UtkarshKumar Just be careful for malicious code, such as `var_evil = "rm -rf /"` – TLP Jul 01 '13 at 09:56