in reply to Treating a variable as a variable in a regular expression?
I solved this by removing the global identifier. !!!!!!!!!!!!
No, you solved it by making the incomplete statement
$function_call = "memcpy(a, b, sizeof(a));"
(no ; terminates the statement) into a complete statement (by adding a ; and then not mentioning it to anyone, possibly even including yourself ;).
c:\@Work\Perl>perl -wMstrict -le "my $function_used = 'memcpy'; my $function_call = 'memcpy(a, b, sizeof(a));'; $function_call =~ s/$function_used//g; print qq{'$function_call'}; " '(a, b, sizeof(a));'
(I'm assuming that by 'problem', you mean the fact that the OPed code will not compile.)
Update: If there's any chance that $function_used may contain regex metacharacters, it's a very good idea to use quotemeta on it at some point, e.g.:
$function_call =~ s/\Q$function_used\E//g;
|
|---|