• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

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!.

Thanks,
Govinda
0
govinda051198
Asked:
govinda051198
  • 2
  • 2
1 Solution
 
thoellriCommented:
Try:
  $str =~ s/[\x0D\x0A]/<p>/g;

:-)
  Tobias
0
 
sludinCommented:
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;

-stephen

0
 
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.

Thanks,
Govinda

0
 
thoellriCommented:
Try:
  $str =~ s/\x0D?\x0A/<p>/g;

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

Thanks for the help.

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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