Greetings,
I need to write a perl script to evaluate a formula based on the contents specified in a configuration file using comma separated value format. For instance, a formula to calculate free swap space in a window system. For the sake of discussion, lets assume there are 3 lines in this file:
127.0.0.1,data,Win32_OperatingSystem,FreeSpaceInPagingFiles,,FreeSpaceInPagingFiles
127.0.0.1,data,Win32_PageFile,FileSize,,PageFileSize
127.0.0.1,formula,SwapUsage,,(FreeSpaceInPagingFiles/PageFileSize)*100
The first two lines define two data points, FreeSpaceInPagingFiles and PageFileSize. The third line defines a formula, SwapUsage and the formula is
(FreeSpaceInPagingFiles/PageFileSize)*100.
The formulas are specified by the users so it can be different for each type of data point. My question is that when we retrievd data for one data, such as FreeSpaceInPagingFiles and I stored it in a hash, such as $hash(FreeSpaceInPagingFiles) = 732448;
How do I evaluate the formula dynamically? In other words, how to replace the formula with real data and get the result?
Thanks for your help,
tmy05
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.