in reply to Accessing Variables in Different Subroutines

1 - If I instantiate a variable outwith the subroutines and give it a value in one subroutine, I am unable to get that value in subsequent subroutines.

You are only calling one subroutine per execution. This should be obvious to you because you call it with $execute->(); and immediately thereafter, you exit;.

The mistake you are making is pretty common for people who are brand new to web development. You are thinking that multiple calls to your CGI script are handled within one execution of the script. That's not the case. The script is executing anew each time you submit your form.

There are different ways around this, but the most common one is to use a cookie to maintain state. Although you can store the state information directly in the cookie, that's not a very robust way to do it. A better way is to store the data on the server somewhere (often in a database) and then use the cookie as a key to get to that data.

"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^2: Accessing Variables in Different Subroutines
by stefl (Acolyte) on Mar 20, 2015 at 08:38 UTC

    Thanks very much. As you can guess, I only started looking at web development just over a week ago, so I'm very much a beginner. Your answer explained my mistake very well, thanks!
    I managed to get around my problem by using hidden parameters (I'd tried this previously but incorrectly and just assumed that it didn't work) and now my script does what I need it to.
    If I start needing to do more web development than I am just now, I'll have a deeper look into other options (but for now this works!)