Uninitialized values in hash

M

mike

Hi,

I am running the following code:

use strict;
use warnings;

my $verbose = 1;
my $info = "[INFO] :";
my $error = "[ERROR]:";

my $configFile = "config.dat"; # Recommended plugins.
my %User_Preferences = ();


####################### Subroutines #######################





#################################### Start Main
#######################################
print "Reading configuration data ...\n";


open FILE, "$configFile" or die "$error Could not open file
$configFile :$! ";

while (<FILE>) {

s/\s+$//;# Remove all \r, \n, ^M from end of line
next if (/^$/);# ignore null lines
next if (/^\s*#/); # ignore comment line.
my ($config_name,$config_val)=split(/\s*=\s/, $_,2);# Split the line
$User_Preferences{$config_name}=$config_val;
$verbose && print "$config_name\n";

}

close FILE;

print "Deploying $User_Preferences{pathdeployunit}";

I get the following output:

Reading configuration data ...
asadminexecutable=C:\sailfin\b22\sailfin\bin>C:\sailfin\b22\sailfin\bin
\asadmin
passwordfile=C:\Documents and Settings\eraonel
\remote_admin_password.txt
user=admin
host=137.58.240.75
port=4848
pathdeployunit=M:\target\complete-ear-0.0.0.1-SNAPSHOT.ear
Use of uninitialized value in concatenation (.) or string at /vobs/
mbv_admin/tools/scripts/test/rdeploy.pl line 39.
Deploying
Compilation finished at Thu Apr 10 08:46:02

Question:

Is not the hash User_Preferences initialized with values when I read
my file? Is there another way to do it?

cheers,

//mike
 
G

Guido Ostkamp

mike said:
$verbose && print "$config_name\n";

I get the following output:

pathdeployunit=M:\target\complete-ear-0.0.0.1-SNAPSHOT.ear

Is not the hash User_Preferences initialized with values when I read
my file? Is there another way to do it?

Apparently the "split" did not work as expected, otherwise you would
no have got the output from the print above - the whole string is in
$config_name, and $config_val is undef, thus the warning.

Regards

Guido
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top