in reply to Re: Text::CSV not able to execute insert query dynamically.
in thread Text::CSV not able to execute insert query dynamically.

hi...its not giving any error.. when I run the 1st insert query its storing the field values of csv file (like 34, 67, 29) but when I run the second insert statement instead...it giving me values like ($row->[0], $row->1 etc). also If I remove \ before $ its failing because it doesn't have any value of $row variable at that time...thanks

  • Comment on Re^2: Text::CSV not able to execute insert query dynamically.

Replies are listed 'Best First'.
Re^3: Text::CSV not able to execute insert query dynamically.
by kennethk (Abbot) on Sep 16, 2014 at 23:03 UTC
    Did you try the suggested code for your insert? Sorry for any lack of clarity in the explanation.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      Hi..sorry for late reply..was off work :) Thanks a lot..It works perfectly. But could you please explain it little further...how u used do block? Thanks again..:)

        A do block just executes the contained code and returns the last thing that was evaluated. In this context, I use it to create a tight scope for the $count and $qs variables. It is functionally equivalent to
        my $count = @$columns; my $qs = join ',', ('?') x $count; my $sql = <<EOSQL; INSERT INTO VoucherMRPDataTable_Frt_TariffModel VALUES ($qs) EOSQL
        except that in the latter case, you'll be carrying around two more variables, one of which has a very generic name.

        Does that clarify things?


        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.