Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Treating a variable as a variable in a regular expression?

by LanX (Saint)
on Jul 08, 2014 at 13:37 UTC ( [id://1092721]=note: print w/replies, xml ) Need Help??


in reply to Treating a variable as a variable in a regular expression?

> $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 :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1092721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-23 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found