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


In reply to Regex error in the second last string by t-rex

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!
  • 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:
    & &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.