Question : A parsing error

For the attached code, I want to parse the attached excel file, take a value src_id from the excel file and delete from a database.

is this assignment allright?
my $worksheet1 =  $workbook->Worksheet("WF");
Somehow I feel it is not.

getting this error--
Can't modify concatenation (.) or string in scalar assignment at DeletePrevPosting.pl , near ""$src_id")"
delete argument is not a HASH or ARRAY element or slice at DeletePrevPosting.pl .
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
#!/usr/bin/perl5.10 -w

use warnings;
use strict;
use Spreadsheet::ParseExcel;
use IO::Scalar;
use Data::Dumper;
use DBI;
use DBD::MSDB2;

my $curr_etl = "wf_OTC_Taxlots_Open";

my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse("/ms/user/s/sayantag/Source.xls");
my $worksheet1 =  $workbook->Worksheet("WF");
#my $worksheet2 =  $workbook->Worksheet("Calc");
print $worksheet1;



for  $worksheet1 ( $workbook->worksheets() ) {
my ( $row_min, $row_max ) = $worksheet1->row_range();
my ( $col_min, $col_max ) = $worksheet1->col_range();

 for my $row ( $row_min .. $row_max ) {##First for##
 for my $col ( $col_min .. $col_max ) {##Second for##
   my $cell = $worksheet1->get_cell( $row, $col );
   if ($col==0 && $row !=0 && ($worksheet1->get_cell($row, 0)->value eq "$curr_etl"))  {
       $col++;
       my $src_id =  $worksheet1->get_cell($row, $col)->value;
       print $src_id;


my $dbh = DBI->connect('dbi:MSDB2:NQ200001', '', '', { 'RaiseError' => 1 }) or
          die "Can't connect to database: $DBI::errstr";

$dbh->do(delete from pfnd.funding_journal_vw fj where fj.SRC_ID = "$src_id"));
$dbh->disconnect;
$workbook->close();
     }
   }
 }
}
Attachments:
 
Attached excel file
 

Answer : A parsing error

That is caused by $src_id being passed in explicitly without interpolation because the sql is enclosed in single quotes.  If you change to one of the below, it should work (or at least give a different error).

$dbh->do("delete from pfnd.funding_journal_vw fj where fj.SRC_ID = \"$src_id\"");
$dbh->do("delete from pfnd.funding_journal_vw fj where fj.SRC_ID = '$src_id'");
Random Solutions  
 
programming4us programming4us