Random Programmer wrote in message <1123157134.444259.263990@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>... >Hello all. Lets say I have a section of code which is run multiple
>times in a program in at least two separate parts of the main program.
>
>I would like to put it into a subroutine, but the problem is that doing
>so will require that I pass on a majority of the program's variables to
>it. My subroutine's "Call" command ends up being several lines long!
>I've thought about summarising the arrays being passed on to just
>vectors with the data to be manipulated and other steps...but I think
>this will end up being more CPU/memory intensive than just copying and
>pasting the code twice instead of passing it on to a subroutine.
>
>Is there any way around this? For example can I just set up my
>subroutines so that they use all of the global variables in the
>program?
Re: variables problem ... > 1) using strict define a global hash variable,... In a subroutine is where you most often use lexical ... I tend to keep a print out in the open, using global variables.... Some, though, practice overkill with lexical variables.... (comp.lang.perl.misc)
Subroutine question ... Lets say I have a section of code which is run multiple... times in a program in at least two separate parts of the main program. ... I would like to put it into a subroutine, but the problem is that doing ... subroutines so that they use all of the global variables in the ... (comp.lang.fortran)
Re: [SPARK] Code safety and information hiding ... I'll accept a small number of well documented global variables sometimes if the alternative is worse. ... Each subroutine has some local variables and each package has some state and together they all cooperate according to what the whole is supposed to do. ... Then I decide to break the system into separate processes, and for the sake of discussion what was a subroutine originally becomes a separate process, all communicating using some form of IPC and still cooperating to achieve the supposed goals. ... (comp.lang.ada)
Re: return and undef ... This subroutine also calls the form_parse ... > do if you want to undef that private variable after it is returned? ...Global variables, like %FORM, are just that - ... That would force you to declare your ... (comp.lang.perl.misc)
Re: Help Constructing Fictional Cross-Religious Movement ... copies of local storage and allows access to the different copies by named reference as an obligatory feature of the language."... I would note, though, that the use of "subroutine" in this explanation seems rather centric to your programming idiom -- I suspect that very few readers, on seeing that, would think that the author was explicitly thinking of subroutines with multiple entry points for doing different things, or of using the subroutine's persistent local data for storing this sort of thing. ... If you, like the Java programmer, didn't have a word for such things, and thought of subroutines as normally being single entry point with no persistent local storage -- would it have been nearly so obvious how to emulate a single-instance object in COBOL? ... (rec.arts.sf.composition)