You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Deepak Mallya <ma...@gmail.com> on 2006/12/11 21:19:01 UTC
Doubt in References and complex datastructures
Hi,
When I try to use complex data structures I get an error saying
Use of uninitialized value in string at C:\Documents and Settings\deepm\My
Documents\practice.pl line 29, <FILE> line 1.
The line of code is as follows:-
for ($i=0;$i<=$#terms;$i++)
{
$wordlistref->{$terms[$i]}->{"postingsref"}->{"$doc"}->{"d1"}->{$termfreq}++;
}
Can anyone help me on this..Do I need to initialise every single hash
???cant I use it as above
Thanks,
Deepak
Re: Doubt in References and complex datastructures
Posted by Deepak Mallya <ma...@gmail.com>.
Michael,
thanks a lot Michael I figured it out using the Data
Dumper..Actually the last attribute wasnt initialised..I changed the code as
follows.
for ($i=0;$i<=$#terms;$i++)
{
$wordlistref->{$terms[$i]}->{"postingsref"}->{"doc"}->{"d1"}->{"termfreq"}++;
}
print
$wordlistref->{$terms[0]}->{"postingsref"}->{"doc"}->{"d1"}->{"termfreq"};
'2003' => {
'postingsref' => {
'doc' => {
'd1' => {
' ' => 1
}
}
}
}
Corrected one
'2003' => {
'postingsref' => {
'doc' => {
'd1' => {
'termfreq' =>
1
}
}
}
}
On 12/11/06, Michael Peters <mp...@plusthree.com> wrote:
>
>
>
> Deepak Mallya wrote:
> > Michael,
> > with no variable but just constants inside(I still get the
> > same error) I am actually trying to build a complex data structure on
> > the fly with dynamic values..what do I need to do?.
>
> What line is the warning coming from? The line where you're doing the
> increment?
> Or the line where you're printing?
>
> If you have doubt as to what your data structure looks like, use
> Data::Dumper to
> peak at it.
>
> > for ($i=0;$i<=$#terms;$i++)
> > {
> >
> >
> $wordlistref->{$terms[$i]}->{"postingsref"}->{"doc"}->{"d1"}->{$termfreq}++;
> > }
> > print
> >
> $wordlistref->{$terms[0]}->{"postingsref"}->{"doc"}->{"d1"}->{$termfreq};
>
> print Data::Dumper::Dumper($wordlistref);
>
> --
> Michael Peters
> Developer
> Plus Three, LP
>
>
Re: Doubt in References and complex datastructures
Posted by Michael Peters <mp...@plusthree.com>.
Deepak Mallya wrote:
> Hi,
> When I try to use complex data structures I get an error saying
> Use of uninitialized value in string at C:\Documents and
> Settings\deepm\My Documents\practice.pl line 29, <FILE> line 1.
>
> The line of code is as follows:-
> for ($i=0;$i<=$#terms;$i++)
> {
>
> $wordlistref->{$terms[$i]}->{"postingsref"}->{"$doc"}->{"d1"}->{$termfreq}++;
> }
>
> Can anyone help me on this..Do I need to initialise every single hash
> ???cant I use it as above
Depends what you mean by "initialize". If you mean create the entry, then no,
Perl does this for you (it's called auto-vivification). If you mean actually
give the entry a defined value before using it, then yes.
In the example above the error message says "uninitialized value in string".
Note the "string" not "hash" part of the warning. I suspect your $doc var is
undefined. It's the only thing I can see that is a string.
--
Michael Peters
Developer
Plus Three, LP