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);
    ----------------

    Thanks,

    - NN
    norfernuman, Jul 1, 2004
    #1
    1. Advertising

  2. norfernuman

    GM Guest

    norfernuman wrote:
    > 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


    --

    gee DOT em ewe tee aitch AT comcast.net
    GM, Jul 1, 2004
    #2
    1. Advertising

  3. norfernuman

    norfernuman Guest

    GM wrote:
    > norfernuman wrote:
    >
    >> 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
    >
    >

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

    Thanks
    norfernuman, Jul 1, 2004
    #3
  4. On Thu, 01 Jul 2004 17:30:04 GMT, norfernuman wrote:
    > 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 }
    John J. Trammell, Jul 1, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Iceberg

    Carriage Returns and sockets

    Iceberg, Sep 6, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,130
    Iceberg
    Sep 6, 2003
  2. Schroeder
    Replies:
    1
    Views:
    520
    Jim Gibson
    Jan 26, 2005
  3. Simon Harris

    Remove Carriage Returns

    Simon Harris, Apr 27, 2005, in forum: ASP General
    Replies:
    3
    Views:
    115
    Simon Harris
    Apr 29, 2005
  4. Steve Anderson
    Replies:
    3
    Views:
    237
    Steve Anderson
    Jun 21, 2004
  5. Jason
    Replies:
    4
    Views:
    116
    Adam Funk
    Aug 7, 2006
Loading...

Share This Page