sql - Perl - From Database to data structure -
I ask a table with a SQL in a database like this:
select col1 For reference, col2 will be an integer value, and the col1 will be the name of an element, for example, col2 by column_name to col2 . Eg
foo, 3 times, 10 I need a data structure where values are vars-> gt; {Valueofcol1} should return the value of col2 . Then
$ vars-> FOO 3
Actually I do not know how to return SQL results to a data structure, I can figure out like this.
You need to bring the access line and create that key.
My $ vars; # My $ sth = $ dbh- & gt; Declare the variable for the hash ref outside the loop (select q {col1, select col2 from column 2}); $ Sth- & gt; Execution; Whereas (my $ res = $ sth-> fetchrow_hashref) {# line $ vars- & gt; {$ Res-> {Col1}} = $ res-> {Col2}; # Build the data structure} Print $ vars- & gt; {FOO}; __END__ 3 You want especially.
Comments
Post a Comment