To clarify, I wasn't looking for help with specific code but rather for a theoretical answer on what behavioural differences to expect when using each of the three string eval variations.
Basically what I deduced from your answers so far:
Option 1 and option 2 are
exactly the same under any circumstance, they will always produce the same result no matter what $$var and $transf contain.
Is this understanding correct?
With regards to option 3 one difference seems to be that $$var will only be replaced by it's value when the eval is invoked. Is there any other behavioural difference when using option 3 instead of option 1?
P.S: In my application $$var is a string that contains a decimal number (can have leading zeroes and won't necessarily be an integer) which varies at run-time, while $transf contains matematical operations which also vary at run-time and which I want eval to apply to $$var and then return the result.
For example $$var could be "09" (or it could be "56.7") and $transf could be "/3+6".
So I case of $$var="09" and $transf="/3+6" I want eval to return 9 (i.e. the result of: 9/3+6).
I had to switch from using option 1 to option 3 because the occasional leading zeros (which are inevitable) were causing eval to interpret the value of $$var as an octal (which I don't want) but now that I'm using option 3 I'm unsure if I might get other unexpected side effects.
Basically I'm uncomfortable using code that I don't fully understand, which is why I'm looking for a comprehensive/theoretical explanation of the consequence of using option 3 instead of option 1.
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.