remove carriage returns

Discussion in 'Perl Misc' started by norfernuman, Jul 1, 2004.

  1. norfernuman

    norfernuman Guest

    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);
     
    norfernuman, Jul 1, 2004
    #1
    1. Advertisements

  2. norfernuman

    GM Guest

    take a look at:

    perldoc -f chomp
     
    GM, Jul 1, 2004
    #2
    1. Advertisements

  3. norfernuman

    norfernuman Guest

    So like an idiot, I should have just chomped it - arrgg ;-)

    Thanks
     
    norfernuman, Jul 1, 2004
    #3
  4. [snip]

    Untested:

    for (@ary) { y/\r\n\t//d }
     
    John J. Trammell, Jul 1, 2004
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.