skooma has asked for the wisdom of the Perl Monks concerning the following question:
I have 2 files. One file contains the variables and values it's in the form of excel sheet. The second file contains the mathematical equation in .txt format. My code has to evaluate the formula in a .txt file line by line using the values from the values extracted for the excel sheet. Note: Each line can contain a different formula.
use strict; use diagnostics; use warnings; use Spreadsheet::ParseXLSX; my %data; #initializing hash my $logfile = $ARGV[0]; #Take the file from command line my $parser = Spreadsheet::ParseXLSX->new(); #Initialize Parser my $workbook = $parser->parse($logfile); #Assign the .xlsx file to b +e parsed if ( !defined $workbook ) { die $parser->error(), ".\n"; #Kill parser if .xlsx file not pr +esent } for my $worksheet ( $workbook->worksheets() ) { #Loop till end of +worksheet my ( $row_min, $row_max ) = $worksheet->row_range(); #Getting + max and min row my ( $col_min, $col_max ) = $worksheet->col_range(); #Getting + max and min col for my $row ( $row_min .. $row_max ) { #Loop till max row in +a sheet for my $col ( $col_min .. $col_max ) { #Loop till max col + in a sheet #Adding Hash Elements from Excel my $name_add = $worksheet->get_cell( $row, $col+2 ); next unless $name_add; my $cell_add = $worksheet->get_cell( $row, $col+3 ); next unless $cell_add; my $name = $field_name_add->value(); my $val = $cell_add->value(); $data{$name} = $val ; } } } #=======================================Reading_Formula_File======== +=============================== my $formulae = $ARGV[1]; open ( RD, $formulae ) or die "Couldnt open file $formulae, $!"; while ( $_ = <RD>){ eval $_; printf("%s",$z); }
The expression does not evaluate at all. I am a newbie in Perl.
|
---|
Back to
Seekers of Perl Wisdom