t-rex has asked for the wisdom of the Perl Monks concerning the following question:
hello
I have a template from which I extract few parameters by using perl regex as follows
template 1: <%= my $capi = ''; if (@{$ctxt{'capi_devices'}}){ $capi = 'afu_op=grpcapp' . "\n" . 'capp=1' . "\n" . 'icnt=200' . "\n" . 'capi_dev=' . join(' ', @{$ctxt{'capi_devices'}})."\n". 'capi_cards=' . @{$ctxt{'capi_devices'}}; } $capi; %> <%= my $marega = ''; if (@{$ctxt{'test'}}){ $marega = 'splthid=' . join(' ' ,@spthid_a). "\n" . 'splthjobops=' . join(' ', @{$ctxt{'test'}}). "\n" ; } $marega; %>
Now I have a generic function which processes this template ( it has many parameters but avoiding for the sake of simplicity ), the problem is when i try to extract the $capi some how it gets bypassed and I get the $marega. Here is the code for processing template
while($inp =~ /<%=(.*?)%>/s) { print "Dollar 1 before eval = $1\n"; $inp =~ s/<%=(.*?)%>/eval $1/es; print"INP after substitution = $inp\n"; } # only the concerned part of code with this extraction is written here
the output i get here is
Dollar 1 before eval = my $capi = ''; if (@{$ctxt{'capi_devices'}}){ $capi = 'afu_op=grpcapp' . "\n" . 'capp=1' . "\n" . 'afusched=1 1 1 0 0 0 0 0' . "\n" . 'afu_type=1 1 1 0 0 0 0 0' . "\n" . 'icnt=200' . "\n" . 'capi_dev=' . join(' ', @{$ctxt{'capi_devices'}})."\n". 'capi_cards=' . @{$ctxt{'capi_devices'}}; } $capi; INP after substitution = splthid=7 splthjobops=0 2 1 1 4 0 2 6 0 3 8 0 4 0 0 # here i expect the $1 contents after evaluation to come that is $capi + should be printed but instead $marega is executed.
i hope i can convey what problem i am facing by this writeup, thanks
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex error in the second last string
by haukex (Archbishop) on Feb 06, 2017 at 09:39 UTC | |
Re: Regex error in the second last string
by NetWallah (Canon) on Feb 06, 2017 at 20:35 UTC |