I'm working on a project for work and I have been using the CGI.pm.  Near the top of my scripts, I put the following lines, among others:

use CGI qw/: standard/; my $q = new CGI;

This allows me to do lines like this:

print $q->redirect(-location=> "otherscript.cgi?ord_id=$ord_id");

However, I have been running into some problems with passing data from one script to the next (i.e., order numbers).  If the script that has the line "new CGI" sends data to another script that also has "new CGI", the data seems to get wiped out by that line in the second script.  I tried modifying the line in the second script to read just:

my $q = CGI;

That solved the passing problem, but it seemed to make the other "print $q->" type lines a little flat or they did odd things.  I know, I'm being vague, but I'm recalling symptoms from frustrating moments.  I tried alternating between "new" and not "new", but that doesn't always work.  I'm just running around in circles putting out fires and starting other ones.

In summary, I don't know what "my $q = new CGI;" does.  Therefore, I don't know when to use it and how to modify it.  Can someone explain to me the concepts behind it so I'll know what to do, please?  Thanks.


In reply to Conceptualizing by Spenser

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.