Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am trying to figure out how to dump some data files I have into a database and I have never tried to do this before. so if I am making a retarded mistake please take it easy on me. so far i have read the data file into a hash, created a dsn and connected to my database using win32::odbc, I am not sure what I need to do next. I have several problems. 1) my data..(not quite what I wanted for some values, this is just a rough test so I am ok with not being 100% here) 2) order of the hash is reversed and I am not sure how to fix it. $values, $key instead of the other way around. and finally the sql, how do I insert using a hash? here is my code so far..
use Win32::ODBC; use DBI; $DSN="Ptest"; $db = new Win32::ODBC("DSN=Ptest;UID=userid;PWD=password;"); if(!($db)){ print "Error connecting"; exit; } else { print "Hey you are connected \n"; } my $file="data.txt"; my %hash=(); open(file,$file) or die; { local $/ = undef; %hash = split /\,/,<file>; $sqlstatement="Insert '$value->{0}' into dbo.Results"; while ( my ($key, $value) = each(%hash) ){ print "$value => $key\n"; if($db->SQL($sqlstatement)){ print "abysmal failure try again"; } close file; ---Data---Sample of data-- 1/5/2009 3:55:30 PM,Login,18.490683,SearchLoad,15.012853,SearchCount,0 +:0.392878,SearchResults,16.048765,SearchSave,6.629372,SearchDelete,9. +614098,SearchDetails,4.587307,TaxLoad,5.215133,TaxResults,0:2.956125, +TaxDetails,5.226226,ClientAdd,4.834234,CMALoad,1.841135,CMASave,12.44 +1073,CMADelete,0.218266,ClientDelete,0.268565,Logout,0.822440,1/5/200 +9 5:04:39 PM,Login,12.841120,SearchLoad,5.733201,SearchCount,0:0.1874 +62,SearchResults,6.998567,SearchSave,1.812129,SearchDelete,0.906065,S +earchDetails,4.108532,TaxLoad,2.343270,TaxResults,0:2.765057,TaxDetai +ls,2.468244,ClientAdd,1.593423,CMALoad,1.655911,CMASave,8.092093,CMAD +elete,0.187461,ClientDelete,0.187461,Logout,0.781090

In reply to sql and hash confusion by grashoper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (10)
As of 2024-04-18 14:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found