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.


In reply to How to evaluate a mathematical formula that is stored in another file? by skooma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.