karrakis has asked for the wisdom of the Perl Monks concerning the following question:
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:$outputarray->[$level] = eval "\"$interpol\"";
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.${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";}}
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: logic within interpolation
by Anonymous Monk on Mar 29, 2013 at 21:35 UTC | |
by karrakis (Novice) on Mar 29, 2013 at 22:04 UTC | |
by kennethk (Abbot) on Mar 29, 2013 at 22:18 UTC | |
by hexcoder (Curate) on Mar 30, 2013 at 18:57 UTC | |
by McA (Priest) on Mar 29, 2013 at 21:40 UTC |