Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
The details of why I need to do this are somewhat sketchy but the contents of the examples should make it clear that what I'm doing is legal and not intended to destroy someone *else's* poorly protected unsanitized eval. At a certain point in the running of a specific algorithm, an eval call is made. That eval looks like this:
$outputarray->[$level] = eval "\"$interpol\"";
I want the output to be dependent on the contents of a regex-captured variable $1. This variable will contain a number (as a string) either of one digit, or more than one digit. I need to make a conditional statement that is evaluated within quotes, so I was hoping to use ${ } as a block instead of a variable call. something like:
${if($1 =~ /\d{2,}/){return "driving a vehicle ${1} lbs over the weigh +t limit";}elsif($1 =~ /\d{1}/){return "driving a vehicle $1 tons over + the weight limit";}}
except that, clearly, if this worked, I wouldn't be here. The logic of this algorithm is separate from the parser that contains the eval. I cannot commingle the two. Due to the constraints of the system, my only option for basing a condition on this temporary variable is to feed that logic through this eval.

I'm not asking whether this is the right way to do it, it seems pretty clear it isn't. I'm just asking if it's *possible* ^_^ (and no, I can't change the structure of the eval. The \"s stay right where they are. The only thing I can modify, at least for the purposes of this experiment, is the string contained by $interpol).

Any thoughts?


In reply to logic within interpolation by karrakis

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (11)
    As of 2014-11-21 11:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (107 votes), past polls