From bug-octave-request at bevo dot che dot wisc dot edu Fri Jan 23 07:39:06 2004 Subject: Re: STR2NUM and nasty side effects From: Alois Schloegl To: "John W. Eaton" CC: bug-octave at bevo dot che dot wisc dot edu Date: Fri, 23 Jan 2004 02:37:21 -0600 John W. Eaton wrote: >On 19-Jan-2004, Schloegl Alois wrote: > >| I was analyzing some ascii files, which contain some configuration >| information. Unexpectingly, the working directory has suddenly >| changed. >| >| I tracked the problem down to STR2NUM. STR2NUM is using EVAL. > >OK, maybe this is undesirable. But if we are going to change str2num, >then I would prefer to have an interface that is compatible with >Matlab. > >I noticed that Matlab's documentation says that str2num uses eval and >that it could evaluate functions which produce side effects, though I >was unable to come up with an example that did. > If you feed the name of a user-defined function (e.g. 'UDFUN') into str2num and UDFUN.M contains global variables, plotting, display, calls to the operating system, etc., you get sideeffects. You are right, this is true for Matlab, as well. Therefore, the use of STR2NUM analyzing arbitrary ASCII files should be strongly discouraged. >In any case, it also >claims that str2double avoids the use of eval, so perhaps we should >have both str2num and str2double that are compatible? > >jwe > You are right, STR2DOUBLE would be correct. I've not thought this. I'll check it into octave-forge. Alois ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------