Hi,

Newish Perl user trying to use do $filename; to read configuration data from a file.

Configuration file consists of:

# set up the database connection variables $db_username = ''; $db_password = 'somepassword'; $db_host = 'localhost'; $db_database = 'adb'; $db_table = 'notactual';

The script consists, so far, of the following code:

#!/usr/bin/perl -w use strict; use diagnostics; my $preprocessdir; my $db_username; my $db_password; my $db_host; my $db_database; my $db_table; my $db_tracelog; my $conf_file; my $return; $conf_file = "/home/kuser/dbconnect.inc.pl"; unless ($return = do $conf_file) { warn "couldn't parse $conf_file: $@" if $@; warn "couldn't do $conf_file: $!" unless defined $return; warn "couldn't run $conf_file" unless $return; } print $db_username; print $db_password; print $db_host; print $db_database; print $db_table;

When run it gives the an error for each of the print lines

Use of uninitialized value in print at ocrgqx_audit_report.pl line 30 +(#1) (W uninitialized) An undefined value was used as if it were alread +y defined. It was interpreted as a "" or a 0, but maybe it was a mi +stake. To suppress this warning assign a defined value to your variables.

I am trying to set variables within the script using a configuration file

So I guess I've got some syntax wrong but I can't see what. Follow up query: am I using do appropriately for configuration files - I'm aware of use Safe and will when this first level of syntax is sorted - may lead to a further question ;-)

Thank you in advance

Steve

In reply to variables not being set from a configuration file by stevemayes

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.