Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-25 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found