I have this function in one of my perl applications, what allows a user to use a regex to parse out some of the data, and it works fine
$data = "this is a test" $expression_text = "(.*)es" $data =~ $expression_text $result = $1 which is 'this is a t';
but if the expression is really a command, replace for example, then it fails..
$data = "this is a test" $expression_text = "s/es/dd/g" $data =~ $expression_text

a particular example is a file name string which was put into a file with single quotes, and on the commandline it needs to be double quotes..

'somefile.dat' = "somefile.dat", s// would do that fine..

but I can't seem to understand the nuance of getting perl to execute it properly.. using re debug,
it shows that the text in the right side variable is treated as the ENTIRE string to match against.
re eval doesn't help.
evl (var = var) doesn't do it.

oh sage ones, show me the light..


In reply to using just variables in a regular exression by sdetweil

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.