Is there ever a good reason to use eval()?

后端 未结 10 1097
清歌不尽
清歌不尽 2020-12-03 20:51

It seems to me that eval() is treated with the same disdain that goto is. And by eval, I mean a function for executing a string as code, as seen in

10条回答
  •  清歌不尽
    2020-12-03 21:27

    Maybe I use sh and perl too much, but I've never seen anyone treat eval with the disdain that goto gets.

    So my answer is: 'eval is suitable when you are writing perl 5 and sh'. The block eval is the primary try/catch mechanism in Perl and its hard to write safe code without it.

提交回复
热议问题