> $function_used isnt being treated as a variable (as you know)

Nope, I doubt this! Even without being able to test the code you posted. (did you?)

memcpy should be deleted now.

My best guess is that in your real code $function_used doesn't contain what you think it should.

Maybe a problem with scoping?

> So how can one solve this? !!!!!!!!!!!! I solved this by removing the global identifier. !!!!!!!!!!!!

Your keyboard is broken, maybe that's the problem?(...??????????)

:)

Cheers Rolf

(addicted to the Perl Programming Language)

update

now I can test, the code you posted explicitly informs you about the wrong semicolon:

> perl $function_used = "memcpy"; $function_call = "memcpy(a, b, sizeof(a));" $function_call =~ s/$function_used//g; Scalar found where operator expected at - line 3, near "$function_call +" (Missing semicolon on previous line?) syntax error at - line 3, near "$function_call " Execution of - aborted due to compilation errors.

and the corrected code doesn't have any of your imagined "problems"

> perl $function_used = "memcpy"; $function_call = "memcpy(a, b, sizeof(a))"; $function_call =~ s/$function_used//g; print $function_call; __END__ (a, b, sizeof(a))

so I think you should better take a look into How (Not) To Ask A Question :)


In reply to Re: Treating a variable as a variable in a regular expression? by LanX
in thread Treating a variable as a variable in a regular expression? by parkinglot

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.