Can't use stringas a HASH ref

B

big DWK

Hi-
I keep getting this error
Can't use string ("10180") as a HASH ref while "strict refs" in use at
.. . .

when I run this code

%prefHash{$id} = $value

the $id and $value are pulled out of a database. I'm sure I'm doing
something stupid wrong, if anyone could clue me in that would be great.

Thanks
 
I

islue

Your code has syntax error.

%prefHash{$id} = $value

should be

$prefHash{$id} = $value
 
A

A. Sinan Unur

Hi-
I keep getting this error
Can't use string ("10180") as a HASH ref while "strict refs" in use at
. . .

when I run this code

%prefHash{$id} = $value

That can't be, as the line above is a syntax error.

Please post a short but complete program that exhibits the probelm you are
experiencing.

Please do read the posting guidelines for this group.

Sinan
 
B

big DWK

You're right, I mistyped it when I copied it from my vim window to
this.

Here's a little more code

my %prefHash = ();

$sth=$dbh->prepare(qq{SELECT id, value from TABLE});

while(my ($id, $value)=$sth->fetchrow_array)
{
$prefHash{$id} = $value; #This is where I get the error
}

This is where I get the error "Can't use string ("10180") as a HASH ref
while "strict refs" in use at . . . ", I've printed out the values in
the loop and there aren't any nulls coming thourgh or anything.

Since I posted the first time I have it working better using

$prefHash{eval($id)}=$value;

at least there are no errors. I do have a new error though when I try
and loop through the hash later, here's the code

bacially after the code above I do this

$obj->preferences(%prefHash);

Here's the function it later gets passed into, it's actually from
Net::Nessus::ScanLite

sub setprefs
{
my $this = shift;
my $h = $this->preferences;
foreach(sort keys %$h) # I get the same error as above here now
{
. . .
}
}

So, am I doing something wrong with the hash initually, or is the
ScanLite code messed up?
 
A

A. Sinan Unur

You're right, I mistyped it when I copied it from my vim window to
this.

Who is right? What did you mistype? Please provide some context when you
reply to a post.
Here's a little more code

But it is still not a self-contained, minimal script that others can
run.
my %prefHash = ();

$sth=$dbh->prepare(qq{SELECT id, value from TABLE});

while(my ($id, $value)=$sth->fetchrow_array)
{
$prefHash{$id} = $value; #This is where I get the error
}

Hmmmm ... Where do you execute the query?

I also sincerely hope that your table is not called TABLE, given that
TABLE is a reserved word in SQL.

Sinan
 
A

axel

big DWK said:
So, am I doing something wrong with the hash initually, or is the
ScanLite code messed up?

Since you do not post any complete meaningful code, how are we supposed
to be able to answer this?

Axel
 
B

big DWK

Sorry, I do execute the query, I figured out my problem, i needed to
derefference the hash when I put it in $obj->preferences like this
$obj->preferences(/%prefHash). Now it works like a champ. Thanks for
your help and sorry for the any trouble.
 
A

A. Sinan Unur

Sorry, I do execute the query,

Again, please provide some context when you reply.
I figured out my problem, i needed to derefference the hash when
I put it in $obj->preferences like this $obj->preferences(/%prefHash).

You did not post a short, complete script that others could run easily.

You pointed to an irrelevant section of your code as the source of the
error message.

You *again* posted a syntax error.

*Sigh*
Now it works like a champ.

Good, I am glad.
Thanks for your help and sorry for the any trouble.

Don't be sorry, don't be grateful, just please, *please*, read the
posting guidelines and try to make a good faith effort to follow them.

Sinan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top