Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

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

In my simplistic example code I assumed that a variable name consists of lower case letters. The regular expression ([a-z]+) finds any consecutive sequence of (at least one) lower case letters. It is then replaced by $data{$1}//' ' where $1 stands for the found sequence. $data{$1} is the value assigned to that sequence ie the variable name. If it does not exist in the hash %data the expression //' ' ensures that a blank is used instead (also makes sure that no warning is issued).

I have used s||| instead of the more common s/// to avoid confusion on the // operator.

In the push statement I store the found sequence as in $1 in the array @error if %data did not contain a value for the variable. This is some kind of crude error handling and I can list the names of variables without values further below in the code.

Again, this is only a simplistic example, and not the only way to look at your requirements. The evil eval is still not fully defused and one could create havoc with mischievous inputs in the values or formulae provided.


In reply to Re^3: How to evaluate a mathematical formula that is stored in another file? by hdb
in thread 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 rifling through the Monastery: (1)
As of 2024-04-18 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found