|
Posted by harryfmudd [AT] comcast [DOT] on October 26, 2005, 11:03 am
Please log in for more thread options
olivier.grant@gmail.com wrote:
[snip!]
> the following line of code
>
> eval("print ".$module."::TSD_VERSION;");
> eval("print(\"module version
> v\".".$ScriptData."::TSD_VERSION);");
>
> will print the correct version number, but if you add a bit more to the
> line to output doesn't work :
>
> eval("Logger::Print(\"Using core module \".$ScriptData.\"
> v\".".$ScriptData.'::TSD_VERSION'.".\"
> (\".".$ScriptData.'::TSD_LAST_UPDATE'.".\")\n\");");
>
> (sorry for the obscure code)
>
Well, there's something to be said for the K.I.S.S. principle. Why build
a big complicated string if you can call Logger::Print directly, and
just eval() the part that needs eval()-ing? Something like
Logger::Print ("Using core module '$ScriptData' v" .
eval ::TSD_VERSION"} .
eval ::TSD_LAST_UPDATE} . "\n");
seems clearer to me.
If you must build a big complicated string, have you printed it before
eval()-ing it, to see what you get? You might also consider using the
"qq{}" construct, so you don't have to escape all the embedded quotes.
Note that in my cold-coded simplification I changed your output by using
the "'" character. If you _must_ have '"', consider Logger::Print
(qq{Using core module "$ScriptData v" ...
Tom Wyant
|