On Oct 26, 6:07 am, [EMAIL PROTECTED] (newBee) wrote:
> I have the fallowing code segment in my code. I want to print my
>
> foreach $document(@documents){
> $valueOfTermD = 0;
> $powerOfTermD = 0;
> foreach $term(keys %termWeightHash){
> if($termWeightHash{$term}{$document}){
> $powerOfTermD = $powerOfTermD +
> $termWeightHash{$term}{$document}*
> $termWeightHash{$term}{$document};
> }
> }
> $valueOfTermD = sqrt($powerOfTermD);
> $hashTermD{$document} = $valueOfTermD;
>
> }
Hey Jeff, thanks for pointing to Data::Dumper, this looks interesting.
By the way, newBee, I have doubt abt ur code is it working? I am just
printing ur code again, with line numbers
1: foreach $document(@documents){
2: $valueOfTermD = 0;
3: $powerOfTermD = 0;
4: foreach $term(keys %termWeightHash){
5: if($termWeightHash{$term}{$document}){
6: $powerOfTermD = $powerOfTermD +
$termWeightHash{$term}{$document}*
$termWeightHash{$term}{$document};
7: }
8: }
9: $valueOfTermD = sqrt($powerOfTermD);
10: $hashTermD{$document} = $valueOfTermD;
11:
12: }
On line 4 u r getting hash reference in $term variable, line 5: u have
a if condition which is checking the $document key of inner hash
(reffered by $term). [Hope i am rt till now?]
so ur condition on line 5 shud be ${$termWeightHash{$term}}
{$document} [u have not dereferenced it properly] ...
same mistake is repeated in line 6, what i feel is that ur line 6 shud
look like this
" $powerOfTermD = $powerOfTermD + ${$termWeightHash{$term}}
{$document}* ${$termWeightHash{$term}}
{$document}; "
let me know if i am rt.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/