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!

In reply to Re^5: Using perl to parse a file and update values into a database by 1nickt
in thread Using perl to parse a file and update values into a database by bhushanQA

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.