http://qs321.pair.com?node_id=110481

--OutpostMir-- has asked for the wisdom of the Perl Monks concerning the following question: (cgi programming)

I think I spent god-knows how long tonight working on setting up a Perl/CGI based image gallery for my site. Saddly, I finnaly get it coded properly (ha!) and I get this error when trying to use the script:

It looks like there was an error:
Your script produced this error: (Maybe you didn't strip carriage returns after a network transfer?)

My copy of Perl (ActivePerl) doesn't seem to have any tools to strip the errant carriage returns out of my script. What am I to do?

Originally posted as a Categorized Question.

  • Comment on Removing carriage returns from source code

Replies are listed 'Best First'.
Re: Removing carriage returns from source code
by blakem (Monsignor) on Sep 06, 2001 at 08:05 UTC
    How about:
    perl -pi.bak -e 's/\r\n/\n/g' myfile.pl perl -pi.bak2 -e 's/\r/\n/g' myfile.pl
    This will translate both Mac EOLs and MS EOLs into Unix like ones.

    -Blake

      Where is the answer here?I'm unable to find anywhere.
      Where is the answer here?I'm unable to find anywhere. Sateesh.. My mailid:sateesh_7@rediffmail.com
Re: Removing carriage returns from source code
by tachyon (Chancellor) on Sep 07, 2001 at 05:14 UTC

    In case you are unfamiliar with using Perl directly on the command line the -pi.bak part makes a backup file with a .bak extension before the -e (for execute) executes the 's/this/that/g' on every line of myfile.pl. For a more permanent solution just write a little script like this:

    #!/usr/bin/perl -w -i.bak use strict; while (<>) { s/this/that/g; print; }

    If you call this script say convert.pl you use it like this:

    C:\>type convert.pl #!/usr/bin/perl -w -i.bak use strict; while (<>) { s/this/that/g; print; } C:\>type this.txt this this this this C:\>perl convert.pl this.txt C:\>type this.txt that that that that C:\>type this.txt.bak this this this this C:\>

    Just change this and that to whatever you want. For Mac that will be \r and \n respectively.

Re: Removing carriage returns from source code
by TStanley (Canon) on Nov 03, 2001 at 22:19 UTC
    And if you are using the vi editor on *nix, you can do the following:
    :%s/^M//g

    To get the Control M character, press Control-V first, then Control-M. TStanley
Re: Removing carriage returns from source code
by Anonymous Monk on Nov 03, 2001 at 06:29 UTC
    It might be those annoying ^M's.
    <CODE>
    #!/usr/locl/bin/perl

    while(<>) {
    s/\cM//g;
    print;
    } <CODE>
    ~
    :w no_cM.pl
    % ./no_cM.pl < annoying_file.txt > ahhh.txt
Re: Removing carriage returns from source code
by TStanley (Canon) on Nov 03, 2001 at 22:20 UTC
    And if you are using the vi editor on *nix, you can do the following:
    :%s/^M//g

    To get the Control M character, press Control-V first, then Control-M.

    TStanley

    Originally posted as a Categorized Answer.

Re: Removing carriage returns from source code
by Anonymous Monk on Sep 29, 2004 at 19:29 UTC
    RMP Validation Errors/Warnings for Facility: Requery DOCUMENT ERRORS Section / Record /Name Error Type Error Message Folder ERROR Certification letter is mis sing. ERROR CBI Substantiation letter i s missing. ERROR Unsanitized RMP with CBI da ta is missing.

    Originally posted as a Categorized Answer.