in reply to Using perl to parse a file and update values into a database

Hi again, what happened when you tried to use Config::Tiny on this file as you were advised previously?

Also, the link you provided on SO is to a related but different question where the original data were inside tables in a Word doc ... but you already have an .ini file, correct?

Remember: Ne dederis in spiritu molere illegitimi!

Replies are listed 'Best First'.
Re^2: Using perl to parse a file and update values into a database
by bhushanQA (Sexton) on Jul 08, 2015 at 11:17 UTC
    yes.. I a using .txt file...
Re^2: Using perl to parse a file and update values into a database
by bhushanQA (Sexton) on Jul 08, 2015 at 11:05 UTC
    Hi.. I am able to read the file and that was working perfect. I am thinking to use the same code with little modification. tried this as well I will post code for you.. have look once
    my $config = Config::Tiny->read('testcase_.txt'); foreach my $section (sort keys %$config) { print "[$section]\n"; foreach my $parameter ( keys %{$config->{$section}}) { $parameter = $config->{$section}->{$parameter} +; #$SQL =~ s/.*\=//g; #print "$SQL\n"; my $sth = $dbh->prepare(qq{update $section set + $prepare where Id = 101}); $sth->execute(); $sth->finish(); print"$parameter\n"; } }
    Now I have to read like table, column and values..

      Looks OK. Would help if you can post your test data file. (UPDATE: I see the file. But It looks like each section is a record, not a table.)

      You should always use placeholders in your calls to DBI.

      my $sql; foreach my $table (sort keys %$config) { my $sql = qq{ insert into $table ( id, balance ) values ( ?, ? ) }; my $sth = $dbh->prepare( $sql ); while (my ($col, $val) = each %{$config->{$table}}) { $sth->execute( $col, $val ); } }
      Remember: Ne dederis in spiritu molere illegitimi!
        yeah sure, below is the text file:
        [Subscriber] Id=101 Account_balance=2000000 [Subscriber1] Id1=102 Account_balance1=3000000
        HI I tried with the '?' placeholders.. still the code is not that flexible
        Hi.. Subscriber is the table..Account balance column name and so on. I think your code is not generic which takes only specific values.. consider a text file where I don't know which are the tables, column and values..