Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Adding value to hash

by bofh_of_oz (Hermit)
on Jul 25, 2005 at 13:13 UTC ( #477800=note: print w/ replies, xml ) Need Help??


in reply to Adding value to hash

Looking at your code, I do not see an error. $temp_hash{$temp_name} is a valid key/value pair of a properly declared hash...

From my own mistakes in the past, here's a suggestion: check the output of your SQL query. It looks like your $sql_result is not defined and so $temp_hash becomes a scalar, which is not defined. Insert a

print "sql_result=($sql_result), temp_name=($temp_name), temp_id=($tem +p_id)\n";
That would help clarify what's going on with the code...

Alternatively, assign $sql_result a value directly for testing and verify the behaviour of the program...

 

UPDATE: tests have shown that in the situation I've described, perl does not complain... it only does if %temp_hash is really not defined. Therefore, I tend to agree with Fletch: it might be the scope...

--------------------------------
An idea is not responsible for the people who believe in it...


Comment on Re: Adding value to hash
Download Code
Re^2: Adding value to hash
by reasonablekeith (Deacon) on Jul 25, 2005 at 13:20 UTC
    quote:
      It looks like your $sql_result is not defined and so $temp_hash becomes a scalar

    What! I'm off to learn java if that's true.

    ---
    my name's not Keith, and I'm not reasonable.
Re^2: Adding value to hash
by wazoox (Prior) on Jul 25, 2005 at 14:09 UTC
    It looks like your $sql_result is not defined and so $temp_hash becomes a scalar, which is not defined.

    Certainly not. $temp_hash{undef} is entirely distinct from $temp_hash.

    use strict; my %t; my $t; my $k; $t{$k}='toto'; $t='titi'; # print 'toto', not 'titi' print $t{$k}, "\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://477800]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-12-18 04:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls