Parts of your problem_space is not quite clear to me, so this is largely a shot in the dark. Answers to the questions below will undoubtedly get you better answers.

Are you getting dbname, uname and p/w from something hardcoded in some other part of your script? ... from a form on a webpage? from the CLI?

Any why do want to obtain them within the sub? The reference to using a file sounds as though it might be rooted in a security concern, but that's merely a guess. An appropriate answer will also depend on whether your reference to "the server" is to a web server (Apache, etc) or to a fileserver or something else?

Despite that, taking a stab in the dark, one way to 'get these variables from a file somewhere else on the server" would be to add a block inside the sub (before line 6) opening (and be sure to test the open) the file, and reading the vars.

Why are you using use strict; in the sub. Does that mean you're not using strict (and warnings!) in main? If so, make your life easier by adding both in the head of your script.


In reply to Re: Database connection by ww
in thread Database connection by rooneyl

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.