G'day all

I am writing 5 scripts, which all use the same mySQL database. I have sorted out the DBI and it all works now :) (Cheers fellow monks!)

The problem is, each of these 5 scripts have to have a section defining the variables such as the username, password, database etc so as to access mySQL.

I'd like to store this information in a file, which they can all access and require(). I understand that 'pointers' are required to to this as I am using strict... however I'm not sure exactly how to use a pointer or where to read up on them. I've tried a search without success...

this is what I currently have in each script
## Read the current vote number from the mySQL database. my $dbh = DBI->connect("DBI:mysql:$database","$username","$passwor +d") || error_fatal ("[ vote.cgi: Admin: Unable to open mySQL database + - $! ]"); my $sth_1 = $dbh->prepare("SELECT current_vote FROM vote_count;"); $sth_1->execute(); my @vote_no = $sth_1->fetchrow_array(); my $current_vote = $vote_no[0];
I'd like to be able to have $current_vote and the other variables worked out in the library file and then I can just use them in the other scripts as this is common to all of them.

I currently have this in the library file
sub return_variables { my $server_root = "/var/www/"; ## MySQL database configuration. my $database = "mercury:localhost"; my $username = "mercurus"; my $password = "mercurus"; my @variables = ("$server_root","$db_database","$db_username", +"$db_password"); return @variables; }
How do I use pointers to access these variables from the library file in the main script? (using strict)

Cheers
lagrenouille

In reply to Includes, strict and pointers. by lagrenouille

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.