PERL Syntax Errors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PERL Syntax Errors
# 1  
Old 06-15-2010
Bug 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
# 2  
Old 06-15-2010
Quote:
Originally Posted by nurani
...
I am a newbie to PERL and working on a script....
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;
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.

Quote:
...
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?)
...
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.

Quote:
...
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.
...
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
# 3  
Old 06-16-2010
If it's available, put the line
Code:
use diagnostics;

near the top of the script to get more explanation for errors. Also, never forget the twins:
Code:
use strict;
use warnings;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding latest file in dir but getting syntax errors

I believe there are couple of syntax issues in my script, couldn't find them :( can someone help me with fixing it to make it work. cd /abcde/ #get the latest filename excluding subdirs filename=`ls -ltr | grep ^- | tail -1 | awk '{print $8}'` #get system date and file timestamp and... (3 Replies)
Discussion started by: simpltyansh
3 Replies

2. Homework & Coursework Questions

Help with shell scrip syntax errors

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: This script will analyse the channels.txt e registrations.txt and it will allow to mage the channels and the... (9 Replies)
Discussion started by: Demas
9 Replies

3. Shell Programming and Scripting

Converting from Linux bash (GNU) to Solaris script syntax errors

Original script written on CentOS 6.3 with GNU bash 4.1.2 Destination system is Solaris 9 with GNU bash 2.05 (not changeable by me) I have a script written on the linux side but now we need to provide a version to another site that "doesn't like linux". I've been going through changing the ] or... (13 Replies)
Discussion started by: oly_r
13 Replies

4. Emergency UNIX and Linux Support

Seek help on shell script syntax errors

I want to delete archivelog files that has been archived and applied from primary database to standby database. This piece of script is working in Linux server. However, I copy it to Unix server with tiny modification. It won't work and generate the error message. I have checked code carefullt... (8 Replies)
Discussion started by: duke0001
8 Replies

5. Shell Programming and Scripting

logging errors using perl

Hi, Can some one please tell me how to redirect only errors to the log file using perl. Thanks, Anjan. ---------- Post updated at 08:41 PM ---------- Previous update was at 08:39 PM ---------- Also, i dont want to use any module. Please tell me in normal way (1 Reply)
Discussion started by: Anjan1
1 Replies

6. Shell Programming and Scripting

line count with if /else - syntax errors

this is the script: ps -ef|grep "x_jobstat 10 v001" > jobstatv001.txt ps -ef |grep "x_jobserver 10 v001" >> jobstatv001.txt #Sample text - each line preceded by 4 spaces # root 133064 102986 0 08:49:28 pts/6 0:00 grep x_jobstat 10 v001 # root 137550 1 0 Nov 08 - 0:28... (6 Replies)
Discussion started by: kwalkner
6 Replies

7. Shell Programming and Scripting

Perl: Backtick Errors

When trying to use backticks for system commands, is there a way to read the error messages if a command doesn't execute properly? I have no problem getting the results if the command is properly executed. Ex. my @result = `dir`; foreach my $line (@result) { print "Result = $line";... (2 Replies)
Discussion started by: kooshi
2 Replies

8. UNIX for Dummies Questions & Answers

I dont really think that the math header has syntax errors

Hi, Mini:Evaluator develop$ make bison -d grammar.y grammar.y: conflicts: 24 shift/reduce flex rules.l cc -0 -o Evaluator grammar.tab.c lex.yy.c -ly -ll -lm In file included from grammar.y:3: /usr/include/architecture/i386/math.h:310: error: syntax error before numeric constant... (1 Reply)
Discussion started by: tcerka
1 Replies

9. Shell Programming and Scripting

perl version for syntax errors

All, Does it matter what perl verios your running when you get syntax errors? on version 5.6.1 the code works fine, but on 5.8.0 the code gets errors? #!/usr/bin/perl #use strict; #use warnings; my $mess = 'messages'; my $mess1 = 'messages.1'; my $mess2 = 'messages.2'; my... (13 Replies)
Discussion started by: bigben1220
13 Replies

10. Shell Programming and Scripting

AWK Syntax errors :/

I recently started as an intern and my manager wanted to see how well I would handle Korn Bourne shell scripting without any prior experience, I have prior programming experience but I keep running into syntax errors with AWK. Please take a look at my simple code and tell me what stupid mistake... (6 Replies)
Discussion started by: yongho
6 Replies
Login or Register to Ask a Question