[Tutor] retrieving a variable from a function

Remco Gerlich scarblac@pino.selwerd.nl
Wed, 14 Nov 2001 14:34:07 +0100


On  0, Cerulean Rodent <cerulean_rodent@yahoo.co.uk> wrote:
> Heya, 
> 
> Haven't posted in ages - however, today I have yet again been stopped in my tracks by a simple task. 
> Suppose I have a script that has several functions; I need to retrieve some data and store it in a 
> variable _within_ a function, and later use this data in a different function. So far all I get is a name 
> error, since the other function doesn't recognize the bloody variable - there must be a way around it, 
> but my brain cells refuse to strike me with a Coder's Satori. Can anybody help?

Although there are a few ways to do this, they have in common that they are
usually the wrong way to solve the problem. You don't usually store data
inside a function.

You probably want to return the result and store it, or let the function
store it inside some global or an object, but it would help if you could
explain a bit more about what you're trying to do; if we have more context,
we can explain the pros and cons of different approaches.

-- 
4Remco Gerlich