Solved

How do I solve this Perl Spreadsheet problem

Posted on 2010-08-17
2
316 Views
Last Modified: 2012-05-10
This is in relation to the question I asked earlier.

http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_26409477.html

Now I am separating all the columns that need manual Matches into another tab in the excel sheet and not using that tab at all.

But after running the below code for the attached excel, getting this error after processing the entire sheet. What should I do?
==========================================

TEST PASSED.





The query is --


                  Select  E.POSTING_EVENT_TYPE_CDE, E.FUNDING_RULE_NME  from PFND.ETL_RULES E where E.POSTING_EVENT_TYPE_CDE = 'PBCLCASHPAY'.

Can't call method "value" on an undefined value at Verify_Col_Value1.pl line 91.
 at Verify_Col_Value1.pl line 30
        main::__ANON__('Can\'t call method "value" on an undefined value at Verify_Co...') called at Verify_Col_Value1.pl line 91



#!/ms/dist/perl5/bin/perl5.10 -w





use MSDW::Version

  'Spreadsheet-WriteExcel' => '2.35',

  'Spreadsheet-ParseExcel' => '0.57',

  'OLE-Storage_Lite'   => '0.19', # Used by Spreadsheet::WriteExcel

  'IO-stringy'         => '2.110',# IO::Scalar may be used by Spreadsheet::WriteExcel

  ;



use MSDW::Version ('DBD-DB2'   => '1.76-9.5.4', # or higher

                   'DBI'       => '1.609', # or higher

                   'DBD-MSDB2' => '1.6');



use warnings FATAL => qw(all);

use Spreadsheet::ParseExcel;

use Spreadsheet::ParseExcel::SaveParser;

use Spreadsheet::WriteExcel::Big;



use strict;

use IO::Scalar;

use Data::Dumper;

use DBI;

use DBD::MSDB2;

use File::Copy qw(cp);

use Carp;







$SIG{__DIE__} = sub { confess @_ };

$SIG{__WARN__} = sub { confess @_ };



my $posting_event_type = "PBCLCASHPAY";



#shift;



my $audit_funding_rule = "PB1";



#shift;

#"PBCLCASHPAY";

#shift;



my $col_fmt = "CCY";



#shift;

#"INPUT"; 



#shift;



#"INPUT";

my $ba_nid = 10180184;



#shift;

#shift; 

#11082557;

my $le_nid = 20000033;



#shift;

#20000050;

#shift;

#my @c_arr = ($ba_nid, $le_nid);

#11082557;



#my $sf = shift;

my $actual_file2 = "/v/region/na/appl/phoenixfunding/etl/data/qa/TgtFiles/delta_LibraPrimeBrokerage.txt";



#shift;



#"/v/region/na/appl/qatools/util/data/reports/SF/OtcTaxlotOpenDelta.txt";



#"/v/region/na/appl/qatools/util/data/reports/SF/OtcTaxlotOpenDelta.txt";

#shift



#my $cc1 = "BA_NID_VAL"; 

 

#shift;

#print "the ba-nid value in Verify Col script is $ba_nid\n"; 



my $sql_parser   = Spreadsheet::ParseExcel->new();

my $sql_workbook = $sql_parser->parse("Value_Type_Query.xls");

my $sql_worksheet = $sql_workbook->worksheet("Queries");



my ( $row_min, $row_max ) = $sql_worksheet->row_range();



for my $row ( $row_min+1 .. $row_max ) {



my $cell =  $sql_worksheet->get_cell($row, 0); 

#print $cell->value . "\n";





my $srl = $sql_worksheet->get_cell($row, 0)->value;

my $cc1 = $sql_worksheet->get_cell($row, 1)->value;

my $vt1 = $sql_worksheet->get_cell($row, 2)->value;

#my $flag =  $sql_worksheet->get_cell($row, 3)->value;



 if (defined $cell and $cell->value eq "$srl") {

   my $cell1 = $sql_worksheet->get_cell($row, 1);

   if (defined $cell1 and $cell1->value eq "$cc1") {

    

   my $cell2 = $sql_worksheet->get_cell($row, 2);

    if (defined $cell2 and $cell2->value eq "$vt1" and $cell2->value eq "$col_fmt" and  $sql_worksheet->get_cell($row, 3)->value eq "D" ) {

      my $query1 = $sql_worksheet->get_cell($row, 4)->value;



      $query1 =~ s/\$le_nid/$le_nid/;

      $query1 =~ s/\$ba_nid/$ba_nid/;

      $query1 =~ s/\$posting_event_type/$posting_event_type/;

      $query1 =~ s/\$audit_funding_rule/$audit_funding_rule/;



      print "\n\nThe First Final Query is --\n\n $query1\n\n";

      system("/ms/dist/perl5/bin/perl5.10", "/ms/user/s/sayantag/Finding_Act_Num2.pl", $query1, $actual_file2);  

        

          }

    elsif (defined $cell2 and $cell2->value eq "$vt1" and $cell2->value ne "NA" and $cell2->value ne "Manual Match Required" and $cell2->value eq "$col_fmt" and  $sql_worksheet->get_cell($row, 3)->value eq "H" ) 

         {my $query1 = $sql_worksheet->get_cell($row, 5)->value;

          print "\n\nThe Hard-coded value is --\n\n $query1\n\n";

         # system("/ms/dist/perl5/bin/perl5.10", "/ms/user/s/sayantag/Finding_Act_Num2.pl", $query1, $actual_file2);

          

         #########################################################################################################







    my @row;

   

    open(SF, $actual_file2) || die "Can't open $actual_file2: $!\n";

    my @data;



    while( <SF> ) {

    chomp;

    push @data, [split /\|/];



   }

   close(SF);



    push @row, $query1;    

    while (my @row) {

    foreach my $line (@data) {

     my $found = 0;

        foreach my $val (@row) {

            $found++ if grep({ $_ eq $val } @$line);



        }



        if ($found == @row)   {

            print "\n\nTEST PASSED.

                  \n\nAt the row ---\n\n

                  @$line

                  \n\nThe Value is --\n\n

                  $query1.\n\n";

        } else {

#            print "\n\nTEST FAILED .

#                  The Value is --

#                  $query1.\n\n";

        }

    }

}



         #########################################################################################################

           }



    elsif (defined $cell2  and $cell2->value eq "NA" and $sql_worksheet->get_cell($row, 3)->value eq "D" ) {

       ##############################################################################################

       my $query1 = $sql_worksheet->get_cell($row, 4)->value;



      $query1 =~ s/\$le_nid/$le_nid/;

      $query1 =~ s/\$ba_nid/$ba_nid/;

      $query1 =~ s/\$posting_event_type/$posting_event_type/;

      $query1 =~ s/\$audit_funding_rule/$audit_funding_rule/;



      print "\n\nThe Second Final Query is --\n\n $query1\n\n";

      system("/ms/dist/perl5/bin/perl5.10", "/ms/user/s/sayantag/Finding_Act_Num2.pl", $query1, $actual_file2);



       ############################################################################################



       }

    else {next;}

        }

       }

 

  

      }

Open in new window

Value-Type-Query.xls
0
Comment
Question by:sunny82
2 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 33459972
Change line 91-93 to this:

my $srl = $sql_worksheet->get_cell($row, 0);
my $cc1 = $sql_worksheet->get_cell($row, 1);
my $vt1 = $sql_worksheet->get_cell($row, 2);
if (not defined $srl or not defined $cc1 or not defined $vt1) {
    warn "row $row has blanks in one or more of columns 0-2 - skipping";
    next;
}
$srl = $srl->value;
$cc1 = $cc1->value;
$vt1 = $vt1->value;
0
 

Author Comment

by:sunny82
ID: 33460074
Thx, it worked. I am closing this question and awarding points. If I have any further doubts tomorrow, I will ask you since, I will expand on more columns in the spreadsheet.

Thx again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel conversion issue with Sql server 14 47
Formula or Macro to determine variance 17 75
ADD New Entries 7 16
Auto populate in Cascade dropdown 3 27
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now