Perl Error Use Not Allowed In Expression
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why is “use” not allowed, as in “use strict;” in Perl 5.14? up vote 8 down vote favorite I am trying to use the following conventions I have been instructed to use for good/proper/safe Perl code for my "Hello, World!" Program: use strict; use warnings; I have created and successfully run the following "Hello World" program using (Strawberry) Perl 5.12 on my main Windows 7 OS: !#/usr/bin/perl use strict; use warnings; print "Hello, World!\n"; What I got back, as expected, was "Hello, World!". What struck me as very odd was that the same program run in terminal on my virtualized Linux Mint 14 OS, using Perl 5.14, produced the following error: "use" not allowed in expression at /PATH/hello_world.pl line 2, at end of line syntax error at /PATH/hello_world.pl line 2, near "use strict" BEGIN not safe after errors--compilation aborted at /PATH/hello_world.pl line 3. I created other "Hello World" programs subsequently without either the use strict; or use warnings; lines, and also one with the -w, which I had seen in some tutorials, indicating, if I am not mistaken, that warnings would be turned on. Both of my alternate versions worked properly in that they produced my expected result: Hello, World! What I cannot be sure of is if I need the use statements in Perl programs from version 5.14 and up or if it is just fine to write the -w at the end of my first line. I would like to think that I could use a consistent header, so to speak, in all of my Perl programs, whether they are Windows or Linux, Perl 5.12 or 5.14 or otherwise. perl shebang use-strict share|improve this question edited Jul 29 '13 at 10:28 doubleDown 4,3131529 asked Jan 13 '13 at 7:13 84adam 5315 5 Did you ftp this to your Linux box? Did you use text mode? –Edward Thomson Jan 13 '13 at 7:19 4 "use" is very
Poetry RecentThreads NewestNodes Donate What'sNew on Aug 04, 2010 at 21:46UTC ( #852981=perlquestion: print w/replies, xml ) Need Help?? 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"; [download] 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 http://stackoverflow.com/questions/14301453/why-is-use-not-allowed-as-in-use-strict-in-perl-5-14 +\" 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 http://www.perlmonks.org/?node_id=852981 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 wher
Perl Xref Perl Style Perl Programming Environment Perl POD documentation Debugging Software Testing Program understanding Pretty Printing Perl Tips Humor Etc Tracking down syntax errors can be troublesome, but it's a skill that comes with http://www.softpanorama.org/Scripting/Perlorama/Debugging/perl_error_checklist.shtml practice. Most of the errors you're likely to experience are going to fall into one of the six categories below. The list below is adapted from Simon Cozen book Beginning Perl: Wrong format of Perl script file on one of the data files If you write Perl script in Windows and then push it to Unix that happens often. It's better to run via dos2unix utility all files perl error "just in case". Missing Semicolons This is one of the most common and most easily avoidable errors. Probably the most common syntax error there is. Every statement in Perl, unless it's at the end of a block, should finish with a semicolon. Sometimes you'll get the helpful hint we got above: (Missing semicolon on previous line?) but otherwise you've just got to find it yourself. Remember that the line perl error use number you get in any error message may well not be the line number the problem occurs on � just when the problem is detected. Perl often diagnose wrong line for this error so you need to look at the line listed as a fuzzy pointer. Missing Open/Close Brackets The next most common error comes when you forget to open or close a bracket or brace. Missed closing braces are the most troublesome, because Perl sometimes goes right the way to the end of the file before reporting the problem. For example: !/usr/bin/perl # missing_braces.plx use warnings; use strict; if (1) { print "Hello"; my $file = shift; if (-e $file) { print "File exists.\n"; } This will give us: perl -w missing_braces.pl Missing right curly or square bracket at braces.plx line 12, at end of line syntax error at braces.plx line 12, at EOF Execution of braces.plx aborted due to compilation errors. > The problem is, our missing brace is only at line 7, but Perl can't tell that. To find where the problem is in a large file, there are a variety of things you can do: Indent your code as we have done to make the block structure as clear as possible