in reply to Having problem to substitute "'"
But you've managed to give no evidence or clear description of this.
I have a list of commands in array which I am extracting and running one by one but when I try to run chdir its throwing error due to "'";
What exactly was the error message you got, and what exactly was the operation that caused the error? The notion of "running commands one by one" is actually quite vague. There are various, very different kinds of operations that could be described this way (because the description is vague), and various different ways they could be done wrong. No point in us trying to guess what you did.
I tried to substitute "'" by $path =~ s/'//g;
for some reason its not working
How do you know it didn't work? And what does "not working" mean, exactly?
and I tried chomp which is also not working
Note that chomp is only supposed to remove the value of $/ from the end of the arg(s) that you pass to it; if the value of $/ happens to not be present at the end of the arg(s), nothing happens. (The chop function is different -- it just removes the last character from its arg(s), whatever the character may be.)
Cheers
Pointing out why we can't help you is a cheery exercise, indeed. (not)
(Update: Forgot to mention... if a variable like $path really does contain one or more apostrophe characters, then $path =~ s/'//g will definitely remove them, and you can test this out independently on the command line -- check the output from the following command:
However, if a file or path name really does contain one or more apostrophes (I feel sorry for you in this case), maybe just stripping them out from command lines is the wrong way to go -- try escaping them instead, or doing other things to protect them from being "interpreted" by a shell as metacharacters.)echo "this isn't a problem if you're using bash" | perl -pe "s/'//g"
|
|---|