remove carriage returns

N

norfernuman

I am trying to remove carriage returns ( and more ) from each element of an array before
using them to create a record for a text file. Somehow I sill keep missing
one once in a while and a carriage return occurs in the middle of an order record.

Here is what I'm doing now.

-------------
open(FILE, ">$dump_file") or die("Couldn't open $dump_file for writing: $!");
while (@ary = $sth->fetchrow_array ()) {
for (@ary) {
s/\t+//g;
s/\r+|\n+//g;
}
print FILE (join ("\t", @ary), "\r\n");
}
close (FILE);
 
G

GM

norfernuman said:
I am trying to remove carriage returns ( and more ) from each element of
an array before
using them to create a record for a text file. Somehow I sill keep missing
one once in a while and a carriage return occurs in the middle of an
order record.

Here is what I'm doing now.

-------------
open(FILE, ">$dump_file") or die("Couldn't open $dump_file for writing:
$!");
while (@ary = $sth->fetchrow_array ()) {
for (@ary) {
s/\t+//g;
s/\r+|\n+//g;
}
print FILE (join ("\t", @ary), "\r\n");
}
close (FILE);
----------------

Thanks,

- NN

take a look at:

perldoc -f chomp
 
J

John J. Trammell

I am trying to remove carriage returns ( and more ) from each element
of an array before using them to create a record for a text file.
Somehow I sill keep missing one once in a while and a carriage return
occurs in the middle of an order record.

[snip]

Untested:

for (@ary) { y/\r\n\t//d }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top