Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Replace all instances of \ with /

Hello,


I'm trying to replace all the instances of \ with /.

I have tried doing:

$content =~ s/\///g;
and
$content =~ tr/\///;

and many various versions trying to escape by adding an extra \ or two!!

Can anyone let me know if it's possible?

Thank you for your help and hints!
Best regards,
0
noshankus
Asked:
noshankus
  • 7
  • 6
1 Solution
 
prady_21Commented:
This works well
hope it helps

$value =~ s/\//\\/g;

0
 
noshankusAuthor Commented:
Nope! Sorry... but you sure you got the right syntax?

I want to replace all \ with /

Those damn commands hurt my eyes!!
0
 
noshankusAuthor Commented:
Nope! Sorry... but you sure you got the right syntax?

I want to replace all \ with /

Those damn commands hurt my eyes!!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
prady_21Commented:
i just tested it in my system, it is working absolutely fine
just cut and copy what is given, it shld work
0
 
noshankusAuthor Commented:
Damn! I was so hoping you were wrong! :)

It still doesn't work on my system. I just get a space instead.
The input is some\thing and when it does it's stuff, I get some thing.

I can't even test it on my local system, as I'm having to do this online through a free provider. - Maybe that has something to do with it... but all the other swaps worked. Damn!

Any other ideas how I might go about this? - Extra help appreciated :)
0
 
prady_21Commented:
i am terribly sorry, i will give it to you in a min, what my prog does is to replace / with \ .

and i am terribly sorry, but i still have the output
$value =~ s/\\/\//g;

but note ::: your $value has to be in single quotes

ie $value = 'some\something\somethng';

bcos if $value = "some\somthing\nothing\toomuch";
in " ", \ gives special meaning to the character
  ie \s becomes space, \t becomes tab and so on

i hope you understand
0
 
prady_21Commented:
and that is the reason why you are getting spaces in your output and not \
0
 
noshankusAuthor Commented:
Oh I see.

Well, the problem is that the string could be quite long, as it's usually a path to a file:

some\thing\else\and\more\etc.jsp

So, you are saying that if the string (which is being sent from a form text area) is too long, then it will recognise all the \'s as spaces?

How would I get around that? :)

Thanks for your time, I really appreciate it :)
0
 
noshankusAuthor Commented:
I just did another swap that swapped the spaces with /

LOL! You'd think it would be easier!

Anyway, thank you very much for your help!
0
 
prady_21Commented:
Can you just give an idea of from where you are getting the text from, and can you just put a piece of code

0
 
noshankusAuthor Commented:
Much appreciated :)
0
 
prady_21Commented:
Can you just give an idea of from where you are getting the text from, and can you just put a piece of code

0
 
prady_21Commented:
Well if you would like it, what you can do is, when you are getting the test, if there is some way you can pass the text as
$content = "some\\value\\somewhere\\something";

then there would be no problem
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now