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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.