in reply to Re^3: Using perl to parse a file and update values into a database
in thread Using perl to parse a file and update values into a database

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..
  • Comment on Re^4: Using perl to parse a file and update values into a database

Replies are listed 'Best First'.
Re^5: Using perl to parse a file and update values into a database
by 1nickt (Canon) on Jul 08, 2015 at 12:18 UTC

    Yes, you are quite right, my code was not generic. Because you have not provided a complete picture of what you want.

    First you said that the .ini file contained DB table info in sections. But then the file you posted contained DB records in sections. And you have still not posted a complete working script that I can test on my machine. It is impossible to help until you do this.

    As I have mentioned to you more than once, including this hour, you should slow down. Of course you are anxious to get a resolution, but people are going to get tired of trying to help you if you do not take the steps necessary to help yourself. This includes posting a well-formed question with a complete working script! Please see and review the guide to posting an effective question.

    Yes, it will take you some minutes to make a test script that demonstrates your problem. But then you will get your answer!

    ( It seems you are maybe getting off track with an .ini file for each user, or for each update statement you want to do. How are you creating the .ini files? It would be helpful if you (slow down and) provide a complete description of what you want to do from start to finish. )

    And of course the code can be made more generic, but I still don't know what you are really working with.

    Update: added where clause to SQL example.

    foreach my $table( @some_list_of_tables ) { ## some code to read another .ini file into $config where ## the sections are cols and the k=v pairs are user=new_val ## ## (for example!) foreach my $col (sort keys %$config) { my $sql = qq{ update $table set $col = ? where user = ?}; my $sth = $dbh->prepare( $sql ); while (my ($user, $new_val) = each %{$config->{$col}}) { $sth->execute( $new_val, $user ); } } }
    Remember: Ne dederis in spiritu molere illegitimi!