PERL Syntax Errors

Hi,

I am a newbie to PERL and working on a script. When running it I get a lot of compilation errors.

The actual command in the program (which is within a case structure) is given below

# This gives the actual count of inquires from a log file (It works fine when I type this on the command line)
# $output is the actual log file name

inq1) grep 'Number of inquiries :' $output | sort -u | awk '{print $5}' > inq1-CTR;

The following error message appears multiple times

Scalar found where operator expected at ./inquires_rpt line 104, near ""Number of inquires:" $output"
(Missing operator before $output?)
String found where operator expected at ./inquiries_rpt line 104, near "awk '{print $5}'"
(Do you need to predeclare awk?)

Please let me know what I need to do to fix this. I am also searching on the net for a solution.

Since I have no background in this, I don't have my debugging skills built up yet to scout for the hot spots.

Thanks

That looks like shell script syntax. It won't work in a Perl program.
The fact that it worked fine on the command line should've given you a clue. If a command or a pipeline works on the shell prompt, then it most probably won't work verbatim in Perl.

The shell is not Perl. And Perl is not the shell.

These are pretty self-explanatory error messages.

"Number of inquiries:" is a literal string. $output is a scalar. Perl expects you to perform some operation on them, hence it complains about a missing operator.

Again, the Perl program doesn't understand "awk" - since it's not a scalar/array/hash etc. (as evidenced by the lack of sigils), the Perl interpreter thinks that it is probably a subroutine or a global variable name that needs to be predeclared.

You'd usually want to try the Perl debugger after you have some familiarity and success with the syntax of Perl, which means you ought to begin with the basics of Perl.
Dumping shell commands in a file and feeding it to the Perl interpreter is like dumping sentences from a German book and passing it off as an English essay.

As for fixing this - if you can explain what you are trying to accomplish, then maybe we could suggest something.

tyler_durden

If it's available, put the line

use diagnostics;

near the top of the script to get more explanation for errors. Also, never forget the twins:

use strict;
use warnings;