Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Uninitialized values in hash

Reply
Thread Tools

Uninitialized values in hash

 
 
mike
Guest
Posts: n/a
 
      04-10-2008
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:\sa ilfin\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
 
Reply With Quote
 
 
 
 
mike
Guest
Posts: n/a
 
      04-10-2008
On 10 Apr, 09:00, Frank Seitz <(E-Mail Removed)> wrote:
> mike wrote:
> > my ($config_name,$config_val)=split(/\s*=\s/, $_,2);# Split the line

>
> ^
> \s*
> Frank
> --
> Dipl.-Inform. Frank Seitz;http://www.fseitz.de/
> Anwendungen für Ihr Internet und Intranet
> Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel



Thanks a lot for the concrete feedback!

//mike
 
Reply With Quote
 
 
 
 
Guido Ostkamp
Guest
Posts: n/a
 
      04-10-2008
mike <(E-Mail Removed)> wrote:
> $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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
Hash#keys, Hash#values order question Ronald Fischer Ruby 0 08-23-2007 09:34 AM
hash.keys and hash.values Mage Ruby 14 08-15-2006 08:44 PM
Hash#values and Hash#keys order Alex Fenton Ruby 1 04-15-2006 05:45 AM



Advertisments