Hi All I'm trying to write a small collection of CGI scripts for various functions. I'd like to be able to have a seperate file for some config data and subroutines that will be used globally.

I've created the file with DB connection info and some other basic stuff and am using "require ./config.pl" in each of the scripts. The problem is that variable declaration in config.pl aren't avaliable in the other scripts. So after connecteing to the DB using the subroutine in config.pl $dbh and $sth aren't exported. The variables in question are initalised outside the subroutines but are in config.pl.

Also passing variables from the running script into a subroutine in config.pl seems to be impossible too, although I suspect thats all related to a namespace type problem. My understanding was that require effectivly made the files into one long file but apparently not


In reply to CGI and require by snorks

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.