Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi,

I've never seen this behaviour before so am questioning my understanding of variables in a Perl CGI environment has been wrong from the start. I was always under the impression that the lifespan of a variable in a CGI script is just during the execution of that script (unless of course they are passed between pages).

I've just noticed that a variable I am using to calculate a value in a Perl CGI script is retained each time the script is called. So the net result is the variable never gets reset back to 0.

As a test, I've created a very simple CGI script to just add 1 to a variable and display it ($test++; print $test;). No other declarations. Run this as a CGI script and the numbers go 1, 2, 3, 4, 5, 6, etc. However, run this in a command shell and it always returns 1.

I'm amazed as I've never seen this behaviour before. And I'm sure I would have done with the Perl CGI I have done over the years.

Hoping someone may put me out of my misery and confirm it's a bug of some sort.

My environment is Windows 7 Ultimate 64-bit SP1, ActivePerl perl5 (revision 5 version 10 subversion 0), Windows IIS.

Many thanks
Gaz

In reply to Perl Variables Being Retained by oioigazza

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found