i'm a dba and just started learning perl (and programming) about week ago...i am hoping some kind soul will help me out.
i'm working on a script to take the results of a benchmark result text file, parse the text, then toss it into a mysql database. the text file is composed of six columns and is many lines long. an example of a line is: count_distinct 25.00 0.48 0.12 0.60 1000
in pseudoCodeSpeak, i wanna grab the file, pass it into an array, grab the first line, parse the line into its six elements, write them to a row in a mysql table which i've already created, then do it again for the next line, then the next, and so on and so forth until there are no lines left. the mysql insert using perl is no big deal, i found an example that works that i'm trying to adapt - but the perl i have is very much incomplete, like there is no reference to the subroutine yet :)
any help is greatly, greatly appreciated. i'm planning on learning perl one step at a time, but i really need this to work soon and i'm sorta stuck in a mental rut...
Thanks in advance for any assistance!!!!
this is what i have so far:use DBI; ###### connect to the database my ($dbh,$sth,$count); $dbh = DBI->connect ("DBI:mysql:host=boognish;database=benchwarmer", "joda","waliays", {PrintError => 0, RaiseError => 1}); ###### name, input, and read the text into an array $input_file = 'RUN-mysql-win2k.txt'; open(INFO, $input_file); @input = <INFO>; ###### slice the array input into six element chunks @input[0,1,2,3,4,5]=@single_line #assign values to the various parts of the single_line array $operation=$single_line[0]; $seconds=$single_line[1]; $usr=$single_line[2]; $sys=$single_line[3]; $cpu=$single_line[4]; $tests=$single_line[5]; sub write_data { my($operation,$seconds,$usr,$sys,$cpu,$tests) = @_; $count = 0; $count += $dbh->do ("INSERT INTO main (operations,seconds,usr,sys,cpu, +tests) VALUES($operation,$seconds,$usr,$sys,$cpu,$tests)
In reply to Trying to process some text... by japhySnyder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |