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
SteveIn reply to variables not being set from a configuration file by stevemayes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |