Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I've just started using perl and was attempting to use a simple program.
#!/usr/bin/perl print "Hello World\n";
However when I went to run in through terminal I get this response. In terminal I am in the folder where the program is located and type in perl hello.pl I get the following error
Backslash found where operator expected at hello.pl line 1, near "rtf1 +\" Backslash found where operator expected at hello.pl line 1, near "ansi +\" Backslash found where operator expected at hello.pl line 1, near "ansi +cpg1252\" Backslash found where operator expected at hello.pl line 1, near "coco +artf1038\" Backslash found where operator expected at hello.pl line 2, near "font +tbl\" Backslash found where operator expected at hello.pl line 2, near "f0\" Backslash found where operator expected at hello.pl line 2, near "fmod +ern\" Backslash found where operator expected at hello.pl line 3, near "red2 +55\" Backslash found where operator expected at hello.pl line 3, near "gree +n255\" Backslash found where operator expected at hello.pl line 4, near "marg +l1440\" Backslash found where operator expected at hello.pl line 4, near "marg +r1440\" Backslash found where operator expected at hello.pl line 4, near "view +w9000\" Backslash found where operator expected at hello.pl line 4, near "view +h8400\" Backslash found where operator expected at hello.pl line 5, near "view +kind0 \" (Missing semicolon on previous line?) Backslash found where operator expected at hello.pl line 6, near "deft +ab720 \" (Missing semicolon on previous line?) Backslash found where operator expected at hello.pl line 6, near "pard +\" Backslash found where operator expected at hello.pl line 6, near "pard +eftab720\" Backslash found where operator expected at hello.pl line 6, near "ql\" Backslash found where operator expected at hello.pl line 8, near "qnat +ural \" (Missing semicolon on previous line?) Backslash found where operator expected at hello.pl line 8, near "f0\" Backslash found where operator expected at hello.pl line 8, near "fs24 + \" (Do you need to predeclare fs24?) Backslash found where operator expected at hello.pl line 9, near "cf0 +#!/usr/bin/perl -w\ \" (Missing semicolon on previous line?) syntax error at hello.pl line 1, near "rtf1\" syntax error at hello.pl line 3, near "red255\" syntax error at hello.pl line 4, near "margl1440\" "use" not allowed in expression at hello.pl line 10, at end of line "use" not allowed in expression at hello.pl line 11, at end of line syntax error at hello.pl line 14, near "}" Execution of hello.pl aborted due to compilation errors.
Does anyone have any idea what I am doing wrong or what is going on with my machine? Thank You

Replies are listed 'Best First'.
Re: Unsure why this isn't working?
by roboticus (Chancellor) on Aug 04, 2010 at 22:11 UTC

    You need to use a TEXT editor rather than a word processor to edit your text. Use notepad and save as text, not RTF or some other format. Word processors put in all kinds of extra information to control fonts, page layout & such.

    If you're in a command-line window and you type out your program, you'll see that it's got quite a bit more than those two lines of code.

    ...roboticus

      Also, if the file was created/edited in Windows and then copied to the *nix system, you'll run into weird issues to differences in formats (such as \r vs. \r\n). I'm speaking from personal experience on this one. :D

      If that's what you did, you'll need to run the dos2unix utility to convert the file to the *nix formatting.

Re: Unsure why this isn't working?
by Your Mother (Archbishop) on Aug 04, 2010 at 22:22 UTC

    You got a good answer from roboticus but there is more to think about. If you take the first line of problem output-

    Backslash found where operator expected at hello.pl line 1, near "rtf1\"

    and put it through google: rtf1 you'll get this kind of thing back: RTF - Rich Text Format (tutorial). Which is an oblique answer: the file is not in plain format and raw code (generally) must be.

    There are *many* hurdles to teaching yourself to program. You just stumbled over one of the first. The thing that sometimes takes much too long to learn is that there are just as many tools and helpers as there are obstacles. If you foster developing investigation skills from the beginning, you'll be on easy street a year or two ahead of what most of us self-taught code monkeys paid. :)

      Which is an oblique answer: the file is not in plain format and raw code (generally) must be.

      When I wrote control software for nuclear reactors, we had to write each program twice. Once in assembler, once using a combination of variable definition tables, prose and Pascal-ish code in Word. The idea was to use as different a mental model as possible.

      The Word doc would serve as the final spec and documentation, but it would also be parsed and compiled so that we could run our test suite against it (in order to compare the results it gave with those from the assembler program).

        That's a *great* story and a really interesting/cool approach. Also, I'm glad it was you writing nuclear reactor software and not me. Better for everyone, I think.

        Is that why there was that "low level" radioactive material leak in a Canadian reactor? ;)
        Seriously..don't you end up with two essentially different programs that test and execute differently?
        Java has a disclaimer not to be used for controlling reactors or missiles..funny stuff
        the hardest line to type correctly is: stty erase ^H