bhushanQA has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

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

    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!
      yes.. I a using .txt file...
      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!
Duplicate: Re: Using perl to parse a file and update values into a database
by 1nickt (Canon) on Jul 08, 2015 at 11:00 UTC

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

    Remember: Ne dederis in spiritu molere illegitimi!
A reply falls below the community's threshold of quality. You may see it by logging in.