Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove New Line Characters

Status
Not open for further replies.

simatics

Programmer
Joined
Apr 16, 2007
Messages
2
Location
TT
Hi all,

I am reading data from an HTML file, and puting this data into
an array.

One of the array values have three 'new line chars' that looks
like a 'square' in the HTML file itself.

It's an address field, so the value looks like this in the
file:

Address Line 1<square>
Address Line 2<square>
Address Line 3

When printed in the perl program, the array field looks like
this:

Address Line 1
Address Line 2
Address Line 3

I would like to extract the data, but it is proving difficult.
Here is the code I am using:

$line = $array_value;
$_ = $line;
/^(.?)\n/;
print $1.$2.$3."\n";

When I run the above script, I get "Address Line 1" printed.
When I replace the reg.ex. with /^(.?)\n(.?)\n/ in an attempt
to grab the second line, NOTHING is printed!


I also tried using the following code to remove the new line
characters, to no avail:


$line =~ tr/\015//;
$line =~ tr/\n//;
$line =~ tr/\r//;

Any help would be greatly appreciated.


Thanks!
 
Code:
$line =~ tr/\r//;
That won't delete the characters: you have to add the /d switch:
Code:
$line =~ tr/\r//d;
 
Hi,

thanks for that tip. I tried it, and I still cannot extract all three lines from the array_field.

Maybe I'm trying to delete the wrong character?

Here are the characters I've tried to delete:

\015
\n
\r
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top