Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
@func is an array containg names. I want to assign values to each name as below, but it does seem to work.

PERL
for ($i=0;$i<10; $i++)
{
	$hash{'$func[$i]'}= $i;
	
}
print $hash{'$func[0]'};


I get an error as below:
Use of uninitialized value in print at D:/eclipse/workspace/Pgm1.pl line 47, <FILE1> line 57.


Please help.

Thanks in advance.
Posted
Updated 15-Aug-12 22:35pm
v3
Comments
Sergey Alexandrovich Kryukov 16-Aug-12 4:19am    
What's wrong? Perl, of course. But if you disagree, I don't want to argue... :-)
--SA
Sergey Alexandrovich Kryukov 16-Aug-12 12:56pm    
Faez, I don't understand why did you remove your nice comment in response to my comment. There was nothing inappropriate in your words...
And I meant that I don't consider that the Perl as a language and technology is worth dealing with, but don't want to argue against Perl proponents, that's it.
--SA
Faez Shingeri 17-Aug-12 5:42am    
My bad! :( I thought my comment had a little sarcastic flavour in it and others too might feel the same. I didn't mean to offend you in any way.
Then I was lazy to type again :p

Your Nice! :)
Sergey Alexandrovich Kryukov 17-Aug-12 10:53am    
This is what I say: when I saw your comment, I did not found anything offending or inappropriate in any way. It was perfectly appropriate; don't be so shy. And by the way, there is nothing wrong in a sarcastic saying; it can be offending but it can also be perfectly correct. Of course, there are many fools who get offense of anything, so what?.. :-)

Cheers,
--SA
Faez Shingeri 22-Aug-12 0:37am    
My smile has reached my eyes when reading your reply.. :))
"so what?.." -- Haha...:-D Ok! Sir Sergey Alexandrovich! I shall definitely not let this happen again...!

Great learning from you, if not Perl :)

Cheers,
Faez

This solved my issue :-D
PERL
for ($i=0;$i<10; $i++)
{
	@hash {$func[$i]} = $i;	
}
print $hash{$func[0]};
 
Share this answer
 
Though i am not familiar with Perl,but i can ask you,Do you initialize your $hash{} function before your code you have given here?If you not,then this is the cause of error.
 
Share this answer
 
Comments
Faez Shingeri 16-Aug-12 4:24am    
Oh Yes, I have defined the hash earlier in the program.
my %hash;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900