473,395 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

"defined $r_libs->{$name} " triggers warning "Use of uninitialized value"

Hi,

I use "defined $r_libs->{$name}" to check first if a key exists in a hash
table. But Perl gives a warning WHENEVER the key exists: "Use of
uninitialized value".

Would u please help to check the script, and let me know the reason? Thanks
in advance.

Liang

----------------------------------
#!/usr/local/bin/perl -w

my %libraries;

#$obj_name='obj1';
#$sect_name='sect1';
#$len='001a2';

print "KKK\n";
add_one_libobj(\%libraries, 'obj1', 'sect1', '001a2');
add_one_libobj(\%libraries, 'obj2', 'sect2', '002a2');

add_one_libobj(\%libraries, 'obj1', 'sect2', '002a2');

add_one_libobj(\%libraries, 'obj3', 'sect3', '003a2');

add_one_libobj(\%libraries, 'obj1', 'sect3', '003a2');

print "@@@\n";

print_lib_res (\%libraries);

print "HHH\n";
#+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++
# put the result into hash table
#----------------------------------------
sub add_one_libobj
{
my ($r_libs, $name, $sect, $len) = @_;

print "add_one_libobj:: %$r_libs, $name\n";

#
# the following line will trigger an Perl warning:
# Use of uninitialized value at map_reader.pl
# do u know what's wrong? thanks. Liang
#
if ( defined $r_libs->{$name} ){
#print " the library exists:: $r_libs->{$name}\n";
$r_libs->{$name}->{$sect} += hex "0x$len";
}else{
my %rec;
$rec{$sect}= hex "0x$len";
$r_libs->{$name}=\%rec;

# print " the library is new:: %$r_libs->{$name}\n";
}
}

sub print_lib_res
{
my ($r_libs) = @_;
my ($name, $sect, $len) ;

#print"print_lib_res:: $r_libs\n";

foreach $name (sort keys %$r_libs){
my $r_sect = %$r_libs->{$name};

#print "name=$name, sect = $r_sect\n";
foreach $sect ( sort keys %$r_sect ){

print <<MSG_1
lib/obj=$name, sect=$sect, len=$r_sect->{$sect};
MSG_1
;

}
}

}
-----------------------------------
output:
-----------------------------------
KKK
add_one_libobj:: %HASH(0x825c68), obj1
add_one_libobj:: %HASH(0x825c68), obj2
add_one_libobj:: %HASH(0x825c68), obj1
Use of uninitialized value at tt.pl line 46.
add_one_libobj:: %HASH(0x825c68), obj3
add_one_libobj:: %HASH(0x825c68), obj1
Use of uninitialized value at tt.pl line 46.
@@@
lib/obj=obj1, sect=sect1, len=418;
lib/obj=obj1, sect=sect2, len=674;
lib/obj=obj1, sect=sect3, len=930;
lib/obj=obj2, sect=sect2, len=674;
lib/obj=obj3, sect=sect3, len=930;
HHH
Jul 19 '05 #1
2 5588
Liang wrote:
Would u please help to check the script, and let me know the reason? Thanks
in advance.


Your script works with perl-5.8.3 after changing one line to
my $r_sect = $r_libs->{$name};
by removing the extraneous % sign.

Try with other versions of perl, and post your problem to
comp.lang.perl.misc not comp.lang.perl .
-Joe
Jul 19 '05 #2

"Joe Smith" <Jo*******@inwap.com> wrote in message
news:86GRc.231703$IQ4.70113@attbi_s02...
Liang wrote:
Would u please help to check the script, and let me know the reason? Thanks in advance.
Your script works with perl-5.8.3 after changing one line to


Thanks Joe. You're right. It works on 5.6.0 as well. The problem occuses on
5.001.
my $r_sect = $r_libs->{$name};
by removing the extraneous % sign.

Try with other versions of perl, and post your problem to
comp.lang.perl.misc not comp.lang.perl .
-Joe

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Peter | last post by:
Hello, First of all, sorry for all the code. I don't know how to explain my problem without it. I have a javascript function which can build a webpage dynamically. A striped down version of...
1
by: Denzil | last post by:
Hi, I am retrieving my DB values and setting them in the MyRS::DoFieldExchange(CFieldExchange* pFX) function. One of these records is a Long datatype and could be "Null" in the DB table. The...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
2
by: forwardtrends | last post by:
I am trying to simply make a div appear and dis-appear. The code I am using is: --- if(!document.getElementById) { document.getElementById = function() {return null;}; } function...
60
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this....
6
by: Brendan | last post by:
Hi, I'm trying to mimic the IPC/messaging system of an specific OS in a portable way by using GCC's library. The IPC system uses buffered asynchronous messages, where any thread can send a...
1
by: NachosRancheros | last post by:
Ok so I just started to program with Python about a week ago and I am trying to make a program that will take the path of a file and a shortcut command and save it to a text file. Eventually I want...
23
by: steve.j.donovan | last post by:
Hi guys, We have the following macro: #define NEXT(type,p) (*((type*)(p))++) It provides a way to poke variable sized data into an array of pcode for a simple VM. e.g,
2
by: jmike | last post by:
I'm using some legacy code that has a user-defined exception in it. The top level program includes this line from TestRunError import * It also imports several other modules. These other...
1
by: Wiseman | last post by:
Hello, I am making a web page and have included a JavaScript named crazy clock. The page displays fine in IE but not in Firefox. The event console says: "event is not defined" at line 143....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.