Substitute operator....

I am trying to replace all occurance of line feed and carriage return (hex value - 0D 0A) with html tag <p>.

Here is the piece of code I am trying

$str = 'asdfj asdflkj
lksdfjlka asdfkj sdfjad
jasdfj afdsflkas';

$str =~ s/\x0D\x0A/<p>/g;

But its not working, can anyone help me!.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

  $str =~ s/[\x0D\x0A]/<p>/g;

What's going on here is dealing with how perl represents and end of line internally.  Internally it is always simply \n not \r\n.  

So even though you are on a PC ( I am supposing you are ) there is no \r ( 0x0D ) in $str.

All you need is:

$str =~ s/\x0A/<p>/g;

or more legibly:

$str =~ s/\n/<p>/g;



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
govinda051198Author Commented:
Text file has occurance of
1. Hex 0D 0A
2. Only Hex 0A

But I want to replace only occurance of
OD and OA with HTML <p> tag (not just 0A)

Can you please help me out?.

Note: I can see above mentioned pattern in Hex dump but perl substite operator is not recognizing - 0D 0A.


  $str =~ s/\x0D?\x0A/<p>/g;

Hope this helps
govinda051198Author Commented:
I was driving crazy. I had other problem in the project. Ofcourse its very simple didn't flash....

Thanks for the help.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.