Passing parameters to subroutines
Posted: Tue Sep 14, 2010 1:06 am
I have a couple of questions related to the handling of parameters that are passed to subroutines. If I run this simple example:
Then I get an error message "SNAME is not defined in %sn = sname". However if I just move the position of the %sn assignment:
then the program runs without error. It appears therefore that subroutine parameters become inaccessible following some kinds of file operations.
The second issue is this: if I remove the %fn=fname line, and just have:
then I get an error "FNAME is not a valid string or scalar name in WFOPEN {FNAME}". Removing the curly brackets doesn't help - just gives a different kind of error. So clearly parameters passed to subroutines are not treated in the same way as ordinary variables.
To prevent these kinds of problems I now always have a few lines of code at the start of any subroutine which assign the values of any passed parameters to variables (e.g. %fn in example above) and then only use those variables in the rest of the subroutine. However this seems a bit of a work-around. Is there something I'm missing or doing wrong?
Thanks
Code: Select all
subroutine process_workfile (string fname, string sname)
%fn = fname
wfopen {%fn}
%sn = sname
endsub
call process_workfile ("example.wf1", "example_series")Code: Select all
subroutine process_workfile (string fname, string sname)
%fn = fname
%sn = sname
wfopen {%fn}
endsubThe second issue is this: if I remove the %fn=fname line, and just have:
Code: Select all
subroutine process_workfile (string fname)
wfopen {fname}
endsubTo prevent these kinds of problems I now always have a few lines of code at the start of any subroutine which assign the values of any passed parameters to variables (e.g. %fn in example above) and then only use those variables in the rest of the subroutine. However this seems a bit of a work-around. Is there something I'm missing or doing wrong?
Thanks