FAQ
Hi there,

i have very strange problem.
I have a simple script which I run
on Windows98 (PC) and it
executed properly. But when I
sent it to someboday by email
who uses Unix ; it give error.


The first 3 lines of the script are
comments in following format.

# comment1
# comment2
# comment3 ..

"the script starts here"

the two dots after 3rd comments are AS IT IS in
the script. After the 3rd line ; there is one blank
line. And after that blank line the sctual script
starts. So the error given by Perl is that

"Illegal character \015 (carriage return) at sample.pl line 4."

In fact the line number 4 is blank(and yes it is carriage
return). But then why should it give error? By the way
sample.pl is the name of the script file. The script runs
properly on my Windows98 but gives above error on
Unix machine. By the way on my Windows98 machine
I use ActivePerl ; I dont know about what Perl interpreter
is used on that remote Unix machine. But anyway I
am surprised to see that just because I left a blank line
the Perl should give error? On the contrary Perl is said
to be quite flexible and forgiving language. And also
I have never come across such an error before myself.
Also the "#" is the first character in all the 3 comments

Pls answer. Its very confusing situation. Once again ;
I have Win98 and using ActivePerl of ActiveState.
I typed my script in simple DOS editor.
Thanks
-Jim

Search Discussions

  • Tanton Gibbs at Feb 6, 2002 at 10:31 am
    You've run across the typical cross-platform issues that arise between Unix
    and Windows. The problem is that Windows uses \r\n to terminate a line
    while Unix just uses \n. When perl on unix sees \r it doesn't know what to
    do because it only expects \n. Therefore, to correct the problem, you need
    to change all \r\n to just \n. A typical way to do this is to run dos2unix
    on the file. However, not all systems come with dos2unix. Therefore, you
    can run

    perl -e "while( <> ) { s/\r\n/\n/g; print; }" infile.txt > outfile.txt

    and have it remove the extraneous \r characters from infile.txt and have it
    written to outfile.txt

    Thanks!
    Tanton
    ----- Original Message -----
    From: "Student of Perl" <perl123@rediffmail.com>
    To: <beginners@perl.org>
    Sent: Wednesday, February 06, 2002 5:18 AM
    Subject: Illegal character error for blank line.

    Hi there,

    i have very strange problem.
    I have a simple script which I run
    on Windows98 (PC) and it
    executed properly. But when I
    sent it to someboday by email
    who uses Unix ; it give error.


    The first 3 lines of the script are
    comments in following format.

    # comment1
    # comment2
    # comment3 ..

    "the script starts here"

    the two dots after 3rd comments are AS IT IS in
    the script. After the 3rd line ; there is one blank
    line. And after that blank line the sctual script
    starts. So the error given by Perl is that

    "Illegal character \015 (carriage return) at sample.pl line 4."

    In fact the line number 4 is blank(and yes it is carriage
    return). But then why should it give error? By the way
    sample.pl is the name of the script file. The script runs
    properly on my Windows98 but gives above error on
    Unix machine. By the way on my Windows98 machine
    I use ActivePerl ; I dont know about what Perl interpreter
    is used on that remote Unix machine. But anyway I
    am surprised to see that just because I left a blank line
    the Perl should give error? On the contrary Perl is said
    to be quite flexible and forgiving language. And also
    I have never come across such an error before myself.
    Also the "#" is the first character in all the 3 comments

    Pls answer. Its very confusing situation. Once again ;
    I have Win98 and using ActivePerl of ActiveState.
    I typed my script in simple DOS editor.
    Thanks
    -Jim



    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
  • Brett W. McCoy at Feb 6, 2002 at 11:51 am

    On Wed, 6 Feb 2002, Tanton Gibbs wrote:

    You've run across the typical cross-platform issues that arise between Unix
    and Windows. The problem is that Windows uses \r\n to terminate a line
    while Unix just uses \n. When perl on unix sees \r it doesn't know what to
    do because it only expects \n. Therefore, to correct the problem, you need
    to change all \r\n to just \n. A typical way to do this is to run dos2unix
    on the file. However, not all systems come with dos2unix. Therefore, you
    can run

    perl -e "while( <> ) { s/\r\n/\n/g; print; }" infile.txt > outfile.txt
    A simpler way with Perl:

    perl -pi -e 's/\cM//g' <file>

    -- Brett
    http://www.chapelperilous.net/
    ------------------------------------------------------------------------
    Does a one-legged duck swim in a circle?
  • William Ampeh at Feb 6, 2002 at 1:57 pm
    In Unix, the person has to do two things

    1./ On the very first line of the file, he/she has to insert the location
    of his/her
    PERL interpreter (the location of the PERL interpreter can be found with
    "which PERL").

    For example;

    redhat1:/home/(38)% which perl
    /opt/local/bin/perl <---------- system's response

    So, in my case, I will insert

    #!/opt/local/bin/perl

    On the first line of the file.


    2./ Remove ^M from the end of every line.
    This could be done by running "dos2unix" on the file, or by simply using
    "search and replace"
    in a Unix-based editor. I normally use vi, and then in command mode enter:

    :1,$s/^M//

    where ^M is created by pressing Ctrl-v followed by Ctrl-m (v and m are
    lower case letters).




    __________________

    William Ampeh (x3939)
    Federal Reserve Board

    __________________

    William Ampeh (x3939)
    Federal Reserve Board
  • Dave Benware at Feb 6, 2002 at 3:00 pm

    Student of Perl wrote:

    Hi there,

    i have very strange problem.
    I have a simple script which I run
    on Windows98 (PC) and it
    executed properly. But when I
    sent it to someboday by email
    who uses Unix ; it give error.

    The first 3 lines of the script are
    comments in following format.

    # comment1
    # comment2
    # comment3 ..

    "the script starts here"

    the two dots after 3rd comments are AS IT IS in
    the script. After the 3rd line ; there is one blank
    line. And after that blank line the sctual script
    starts. So the error given by Perl is that

    "Illegal character \015 (carriage return) at sample.pl line 4."

    In fact the line number 4 is blank(and yes it is carriage
    return). But then why should it give error? By the way
    sample.pl is the name of the script file. The script runs
    properly on my Windows98 but gives above error on
    Unix machine. By the way on my Windows98 machine
    I use ActivePerl ; I dont know about what Perl interpreter
    is used on that remote Unix machine. But anyway I
    am surprised to see that just because I left a blank line
    the Perl should give error? On the contrary Perl is said
    to be quite flexible and forgiving language. And also
    I have never come across such an error before myself.
    Also the "#" is the first character in all the 3 comments

    Pls answer. Its very confusing situation. Once again ;
    I have Win98 and using ActivePerl of ActiveState.
    I typed my script in simple DOS editor.
    Thanks
    -Jim

    Did you copy & paste it into the email or send as an attachment?
    It is probably your email client that is causing the problem.

    I used Wordpad for over a year and never had the problem, except
    once when I posted some code on my web site for unix users to download.
    It was the web that added the CR's.

    Bompa
  • John W. Krahn at Feb 6, 2002 at 11:01 pm

    Student Of Perl wrote:

    Hi there, Hello,
    i have very strange problem.
    I have a simple script which I run
    on Windows98 (PC) and it
    executed properly. But when I
    sent it to someboday by email
    who uses Unix ; it give error.

    The first 3 lines of the script are
    comments in following format.

    # comment1
    # comment2
    # comment3 ..

    "the script starts here"

    the two dots after 3rd comments are AS IT IS in
    the script. After the 3rd line ; there is one blank
    line. And after that blank line the sctual script
    starts. So the error given by Perl is that

    "Illegal character \015 (carriage return) at sample.pl line 4."

    In fact the line number 4 is blank(and yes it is carriage
    return). But then why should it give error? By the way
    sample.pl is the name of the script file. The script runs
    properly on my Windows98 but gives above error on
    Unix machine. By the way on my Windows98 machine
    I use ActivePerl ; I dont know about what Perl interpreter
    is used on that remote Unix machine. But anyway I
    am surprised to see that just because I left a blank line
    the Perl should give error? On the contrary Perl is said
    to be quite flexible and forgiving language. And also
    I have never come across such an error before myself.
    Also the "#" is the first character in all the 3 comments

    Pls answer. Its very confusing situation. Once again ;
    I have Win98 and using ActivePerl of ActiveState.
    I typed my script in simple DOS editor.
    On Unix there is a utility called dos2unix (IIRC) that can convert DOS
    text to Unix text, if not then s/he can use the tr program:

    tr -d '\015' < sample.pl > newsample.pl

    On the Windows side you could use a programming editor (like UltraEdit)
    that can save files in the Unix text format. AFAIK Perl can run files
    on Windows in this format.



    John
    --
    use Perl;
    program
    fulfillment

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedFeb 6, '02 at 10:17a
activeFeb 6, '02 at 11:01p
posts6
users6
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase