in reply to Re: array/hash - reference and dereference
in thread array/hash - reference and dereference

O..my mistake..%hash %ages Sorry.
%ages = ('Martin' => 0, 'Sharon' => 0, 'Rikke' => 0); #this way? @insert = \%hash; #at this point, what is the correct way to save the hash into an array +? $insert[0] = $ages->{‘Sharon’}; $insert[1]=$ages->{'Martin’}; %ages = ('Martin' => 28, 'Sharon' => 35, 'Rikke' => 29); : : $sqlquery -> execute(@insert);
My idea is: When the script start, I don't have the hash values. So,I want to create "pointer" points to the hash. And "save" the specific hash value into an array. Later, when the hash values are fetched, I can just run:
$sqlquery -> execute(@insert);
Please advise. Thanks.

Replies are listed 'Best First'.
Re^3: array/hash - reference and dereference
by fullermd (Vicar) on Jan 09, 2009 at 04:45 UTC

    It sounds like a lot more trouble than just making a mkinsert() function.

    %ages = [...] # Finally filled in $sqlquery->execute(mkinsert(%ages));

    You could store references to the hash elements into the array instead. But you'd have to explicitly dereference them, and it would mostly serve to confuse people reading the code. Why not make it simple?

Re^3: array/hash - reference and dereference
by Anonymous Monk on Jan 09, 2009 at 03:39 UTC
    O..Sorry...my mistake..%hash %ages
    %ages = ('Martin' => 0, 'Sharon' => 0, 'Rikke' => 0); #this way? @insert = \%ages; #at this point, what is the correct way to save the hash into an array +? $insert[0] = $ages->{‘Sharon’}; $insert[1]=$ages->{'Martin’}; %ages = ('Martin' => 28, 'Sharon' => 35, 'Rikke' => 29); : : $sqlquery -> execute(@insert);
    My idea is: When the script start, I don't have the hash values. So,I want to create "pointer" points to the hash. And "save" the specific hash value into an array. Later, when the hash values are fetched, I can just run:
    $sqlquery -> execute(@insert);
    Please advise. Thanks.