in reply to Re: (tye)Re2: Eval and $@% ...
in thread Eval and $@% ...
I see your code as similar to rewriting:
as eval( "do_th" . (something?"is":"at") . "()" ); Sure, you can make that work. But what is the point? Stringy eval has to recompile code every time it is run. Unless you are very careful, it can hide serious errors (and you weren't careful in your original code and neither was I in any of the code using eval that I posted in this thread). It can leak memory.if( something ) { do_this(); } else { do_that(); }
I just don't see any point to you using stringy eval here. I only use stringy eval as a last resort. Reaching for that tool too quickly is a common mistake when learning Perl so most experienced Perl programmers discourage it. It is easy to use stringy eval incorrectly.
Ok ... so what I was missing was the {}.
Huh? I didn't add any braces. The main difference between your use of eval and mine was that you expanded the value of $_[0] (by using double quote) while I passed eval the literal string '$_[0]'. I left the {} out of the non-eval code since I was using $ref and not $_[0] so the braces aren't needed.
That would fail if you put use strict 'refs' in the eval, right?
No, my code was using hard reference (not symbolic references) and so use strict 'refs' wouldn't have a problem with it (except, perhaps, for the GLOB dereferencing; I don't use GLOBs as references so I don't track the details of doing that). Your code would only work if $_[0] contained a variable name, causing the eval to use symbolic references.
- tye (but my friends call me "Tye")
|
|---|