?
Solved

How do I solve this Perl Spreadsheet problem

Posted on 2010-08-17
2
Medium Priority
?
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

764 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