Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: Sorting hash values according to order of an array

by mt2k (Hermit)
on Nov 24, 2002 at 02:13 UTC ( [id://215462]=note: print w/replies, xml ) Need Help??


in reply to Re: Sorting hash values according to order of an array
in thread Sorting hash values according to order of an array

my @columns = map { substr($_,1) } keys %{$q{'-values'}};
Um, all that does is create a list of the columns with the first letter of the column name missing...

Anyhow, about specifying the columns in any order in the SQL query, would the following code always work correctly?

my $ph = join ', ', ('?') x values %{$q{'-values'}}; my $sth = $self->{$db_handle}->prepare( "INSERT INTO $q{'-table'} (" . join(',', keys %{$q{'-values'}}) . ") VALUES($ph)" ); $sth->execute(values %{$q{'-values'}});

All I'm really asking is whether the order of keys %hash and values %hash are always the same in perspective to each other...

Update: lol, as soon as I finished posting this post, your update was there :) I understand now why you supplied the code you did. It was to get rid of the hyphens you thought were there :)

Replies are listed 'Best First'.
Re^3: Sorting hash values according to order of an array
by tadman (Prior) on Nov 24, 2002 at 02:51 UTC
    I've been reassured by many that yes, the order will be the same. I think the only condition is that you don't do anything crazy like change the hash between calling values and keys. This isn't an issue as long as you have a single thread, but with threads now being more supported, your mileage may vary.

    It's pretty risky to just throw things in to a table without naming names. You could delete a column and replace it with a different one with the same type, and you'd be populating the wrong columns with nary a hint of an error.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found