perl version for syntax errors


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl version for syntax errors
# 8  
Old 05-12-2010
Those errors have nothing to do with any versions, but are syntax errors from Perl itself. Check your code and make sure that it's correct.

As for the versions:
  • OS and version:
    Code:
    uname -sr

  • Current shell:
    Code:
    awk -vuser=$USER -F: '$1 ~ user {print $NF}' /etc/passwd

  • Perl version: perl -v
  • Shell version: one of these:
    Code:
    echo ${.sh.version}
    echo $BASH_VERSION
    echo $version


And again, how do you invoke the script on the two different platforms? Meaning, what do you type to start it?
# 9  
Old 05-12-2010
... and the OP should post the entire Perl code ...
# 10  
Old 05-12-2010
Pludi,

On both platforms all I do (and have done) is ./script.pl, and then they run.

radoulov,

Code:
#!/bin/perl
use strict;
use warnings;
#*********************************************************** defining variables
my $mess='messages';
my $mess1='messages.1';
my $mess2='messages.2';
my $mess3='messages.3';
my $mess4='messages.4';
#********************************** checking for existence of defined variables
if (-e $mess4) {
  print "File $mess4 exists.\n" }
else {
  print "File $mess4 does not exist. Creating $mess4 ...\n";
  open (MESS4, ">$mess4") or die $!;
  close(MESS4); }
if (-e $mess3) {
  print "File $mess3 exists.\n" }
else {
  print "File $mess3 does not exist. Creating $mess3 ...\n";
  open (MESS3, ">$mess3") or die $!;
  close(MESS3); }
if (-e $mess2) {
  print "File $mess2 exists.\n" }
else {
  print "File $mess2 does not exist. Creating $mess2 ...\n";
  open (MESS2, ">$mess2") or die $!;
  close(MESS2); }
if (-e $mess1) {
  print "File $mess1 exists.\n" }
else {
  print "File $mess1 does not exist. Creating $mess1 ...\n";
  open (MESS1, ">$mess1") or die $!;
  close(MESS1); }
if (-e $mess) {
 print "File $mess exists.\n"; }
else {
  print "File $mess does not exist. There is nothing to copy!\n";
  exit; }
my $filesize = -s "messages";
if ($filesize == 0) {
  print "File $mess is empty! Aborting ...\n";
  exit;}
else {
  print "Copying ...\n"; }
#*************************************************************** moving process
#copy content from mess3 to mess 4
  open (MESS4, ">>$mess4") or die $!;
  open (MESS3, "$mess3") or die $!;
  while (<MESS3>) {
  chomp($_);
  printf MESS4 "$_\n"; }
  close(MESS4);
  close(MESS3);
#create fresh mess3
  open (MESS3, ">$mess3") or die $!;
  close(MESS3);
#copy content from mess2 to mess3
  open (MESS3, ">>$mess3") or die $!;
  open (MESS2, "$mess2") or die $!;
  while (<MESS2>) {
  chomp($_);
  printf MESS3 "$_\n"; }
  close(MESS3);
  close(MESS2);
#create fresh mess2
  open (MESS2, ">$mess2") or die $!;
  close(MESS2);
#copy content from mess1 to mess2
  open (MESS2, ">>$mess2") or die $!;
 open (MESS1, "$mess1") or die $!;
  while (<MESS1>) {
  chomp($_);
  printf MESS2 "$_\n"; }
  close(MESS2);
  close(MESS1);
#create fresh mess1
  open (MESS1, ">$mess1") or die $!;
  close(MESS1);
#copy content from mess to mess1
  open (MESS1, ">>$mess1") or die $!;
  open (MESS, "$mess") or die $!;
  while (<MESS>) {
  chomp($_);
  printf MESS1 "$_\n"; }
  close(MESS1);
  close(MESS);
#create fresh mess
  open (MESS, ">$mess") or die $!;
  close(MESS);

Moderator's Comments:
Mod Comment For the last time: code tags are closed using [/code]. Or just use the # symbol above the editing box.

thanks!
Ben

Last edited by pludi; 05-12-2010 at 05:43 AM..
# 11  
Old 05-12-2010
This code works fine on my Cygwin.

You posted 90 lines of code but the errors above refer to lines 92 and above ...
# 12  
Old 05-12-2010
It works find for me on one system too...I just cant figure out why not the other system.

Here is the code one more time...just to ensure I copied it right,

Code:
#!/usr/bin/perl
 
#use strict;
#use warnings;
 
my $mess = 'messages';
my $mess1 = 'messages.1';
my $mess2 = 'messages.2';
my $mess3 = 'messages.3';
my $mess4 = 'messages.4';
 
if (-e $mess4)
{print "File $mess4 exists.\n"}
else {
        print "File $mess4 does not exist. Creating $mess4...\n";
        open (MESS4, ">$mess4") or die $!;
        close (MESS4); }
 
if (-e $mess3)
 {
        print "File $mess3 exists.\n"}
else {
        print "File $mess3 does not exist. Creating $mess3..\n";
        open (MESS3, ">$mess3") or die $!;
        close (MESS3);}
 
if (-e $mess2)
 {
        print "File $mess2 exists.\n"}
else {
        print "File $mess2 does not exist. Creating $mess2..\n";
        open (MESS2, ">$mess2") or die $!;
        close (MESS2);}
 
if (-e $mess1)
 {
        print "File $mess1 exists.\n"}
else {
        print "File $mess1 does not exist.  Creating $mess1..\n";
        open (MESS1, ">$mess1") or die $!;
        close (MESS1);}
 
if (-e $mess)
 {
        print "File $mess exist.\n";}
else {

        print "File $mess does not exist. There is nothing to copy!\n"
exit; }
 
my $filesize = -s "messages";
        if ($filesize == 0) {
        print "File $mess is empty! Aborting ...\n";
exit; }
else {
        print "Copying ...\n";}
 
open (MESS4, ">>$mess4") or die $!;
open (MESS3, "$mess3") or die $!;

while (<MESSS3>) {
        chomp ($_);
        printf MESS4 "$_\n"; }
        close (MESS4);
        close (MESS3);
 
open (MESS3, ">$mess3") or die $!;
        close (MESS3);
 
open (MESS3, ">>$mess3") or die $!;
open (MESS2, "$mess2") or die $!;
 
while (<MESS2>) {
        chomp ($_);
        printf MESS3 "$_\n; }
        close (MESS3);
        close (MESS2);
 
open (MESS2, ">$mess2:) or die $!;
        close (MESS2);
 
open (MESS2 ">>$mess2") or die $!;
open (MESS1 "$mess1") or die $!;
 
while (<MESS1>) {
        chomp ($_);
        printf MESS2 "$_\n; }
        close (MESS2);
        close (MESS1);

open (MESS1, ">$mess1") or die $!;
        close (MESS1);
 
open (MESS1, ">>$mess1") or die $!;
open (MESS, "$mess) or die $!;
 
while (<MESS>) {
        chomp ($_);
        printf MESS1 "$_\n"; }
        close (MESS1);
        close (MESS);
 
open (MESS, ">$mess") or die $!;
close (MESS);

It didnt put the spaces in there last time. prompt>perl ./myscript.pl
Still getting the errors:

String found where operator expected at line 95, near "open (MESS1, ""
(Might be a runaway multi-line "" string starting on line 92)
(Missing semicolon on previous line?)
String found where operator expected at line 96, near "open (MESS, ""
(Might be a runaway multi-line "" string starting on line 95)
(Missing semicolon on previous line?)
Scalar found where operator expected at line 96, near "open (MESS, "$mess"
(Do you need to predeclare open?)
syntax error at line 50, near "exit"
syntax error at line 80, near "$mess2:"
(Might be a runaway multi-line "" string starting on line 76)
Missing comma after first argument to open function at line 83, near "">>$mess2") "
Missing comma after first argument to open function at line 84, near ""$mess1") "
syntax error at line 95, near "open (MESS1, ""
Missing right curly or square bracket at line 105, at end of line
syntax error at line 105, at EOF
Execution of ./myscript.pl aborted due to compilation errors.

Thanks
Ben
# 13  
Old 05-12-2010
Check my comments:

Code:
#!/usr/bin/perl
 
#use strict;
#use warnings;
 
my $mess = 'messages';
my $mess1 = 'messages.1';
my $mess2 = 'messages.2';
my $mess3 = 'messages.3';
my $mess4 = 'messages.4';
 
if (-e $mess4)
{print "File $mess4 exists.\n"}
else {
        print "File $mess4 does not exist. Creating $mess4...\n";
        open (MESS4, ">$mess4") or die $!;
        close (MESS4); }
 
if (-e $mess3)
 {
        print "File $mess3 exists.\n"}
else {
        print "File $mess3 does not exist. Creating $mess3..\n";
        open (MESS3, ">$mess3") or die $!;
        close (MESS3);}
 
if (-e $mess2)
 {
        print "File $mess2 exists.\n"}
else {
        print "File $mess2 does not exist. Creating $mess2..\n";
        open (MESS2, ">$mess2") or die $!;
        close (MESS2);}
 
if (-e $mess1)
 {
        print "File $mess1 exists.\n"}
else {
        print "File $mess1 does not exist.  Creating $mess1..\n";
        open (MESS1, ">$mess1") or die $!;
        close (MESS1);}
 
if (-e $mess)
 {
        print "File $mess exist.\n";}
else {

        print "File $mess does not exist. There is nothing to copy!\n" # missing semicolon ...
exit; }
 
my $filesize = -s "messages";
        if ($filesize == 0) {
        print "File $mess is empty! Aborting ...\n";
exit; }
else {
        print "Copying ...\n";}
 
open (MESS4, ">>$mess4") or die $!;
open (MESS3, "$mess3") or die $!;

while (<MESSS3>) {
        chomp ($_);
        printf MESS4 "$_\n"; }
        close (MESS4);
        close (MESS3);
 
open (MESS3, ">$mess3") or die $!;
        close (MESS3);
 
open (MESS3, ">>$mess3") or die $!;
open (MESS2, "$mess2") or die $!;
 
while (<MESS2>) {
        chomp ($_);
        printf MESS3 "$_\n; }  # missing closing quote
        close (MESS3);
        close (MESS2);
 
open (MESS2, ">$mess2:) or die $!; # missing closing quote
        close (MESS2);
 
open (MESS2 ">>$mess2") or die $!;  # missing comma
open (MESS1 "$mess1") or die $!; # missing comma
 
while (<MESS1>) {
        chomp ($_);
        printf MESS2 "$_\n; } # missing closing quote
        close (MESS2);
        close (MESS1);

open (MESS1, ">$mess1") or die $!;
        close (MESS1);
 
open (MESS1, ">>$mess1") or die $!;
open (MESS, "$mess) or die $!; # quote ...
 
while (<MESS>) {
        chomp ($_);
        printf MESS1 "$_\n"; }
        close (MESS1);
        close (MESS);
 
open (MESS, ">$mess") or die $!;
close (MESS);



---------- Post updated at 11:33 AM ---------- Previous update was at 11:27 AM ----------

This should work:

Code:
#!/usr/bin/perl
 
#use strict;
#use warnings;
 
my $mess = 'messages';
my $mess1 = 'messages.1';
my $mess2 = 'messages.2';
my $mess3 = 'messages.3';
my $mess4 = 'messages.4';
 
if (-e $mess4)
{print "File $mess4 exists.\n"}
else {
        print "File $mess4 does not exist. Creating $mess4...\n";
        open (MESS4, ">$mess4") or die $!;
        close (MESS4); }
 
if (-e $mess3)
 {
        print "File $mess3 exists.\n"}
else {
        print "File $mess3 does not exist. Creating $mess3..\n";
        open (MESS3, ">$mess3") or die $!;
        close (MESS3);}
 
if (-e $mess2)
 {
        print "File $mess2 exists.\n"}
else {
        print "File $mess2 does not exist. Creating $mess2..\n";
        open (MESS2, ">$mess2") or die $!;
        close (MESS2);}
 
if (-e $mess1)
 {
        print "File $mess1 exists.\n"}
else {
        print "File $mess1 does not exist.  Creating $mess1..\n";
        open (MESS1, ">$mess1") or die $!;
        close (MESS1);}
 
if (-e $mess)
 {
        print "File $mess exist.\n";}
else {

        print "File $mess does not exist. There is nothing to copy!\n";
exit; }
 
my $filesize = -s "messages";
        if ($filesize == 0) {
        print "File $mess is empty! Aborting ...\n";
exit; }
else {
        print "Copying ...\n";}
 
open (MESS4, ">>$mess4") or die $!;
open (MESS3, "$mess3") or die $!;

while (<MESSS3>) {
        chomp ($_);
        printf MESS4 "$_\n"; }
        close (MESS4);
        close (MESS3);
 
open (MESS3, ">$mess3") or die $!;
        close (MESS3);
 
open (MESS3, ">>$mess3") or die $!;
open (MESS2, "$mess2") or die $!;
 
while (<MESS2>) {
        chomp ($_);
        printf MESS3 "$_\n"; }
        close (MESS3);
        close (MESS2);
 
open (MESS2, ">$mess2") or die $!; 
        close (MESS2);
 
open (MESS2, ">>$mess2") or die $!;
open (MESS1, "$mess1") or die $!;
 
while (<MESS1>) {
        chomp ($_);
        printf MESS2 "$_\n"; } 
        close (MESS2);
        close (MESS1);

open (MESS1, ">$mess1") or die $!;
        close (MESS1);
 
open (MESS1, ">>$mess1") or die $!;
open (MESS, "$mess") or die $!; 
 
while (<MESS>) {
        chomp ($_);
        printf MESS1 "$_\n"; }
        close (MESS1);
        close (MESS);
 
open (MESS, ">$mess") or die $!;
close (MESS);

This User Gave Thanks to radoulov For This Post:
# 14  
Old 05-12-2010
Pludi,

The information you wanted:

OS and Version-
Not working: linux 2.4.34.2-skas3
Working: HP-UX B.11.11

Current shell:
Not working: /bin/bash
Working: command didn't work

Perl Version:
Not working:
This is perl, v5.8.0 built for i386-linux-thread-multi
(with 1 registered patch, see perl -V for more detail)
Working:
This is perl, v5.6.1 built for PA-RISC1.1

Shell version:
Not working: 2.05b.0(1)-release
Working: command didn't work


Ben

---------- Post updated at 06:11 AM ---------- Previous update was at 05:35 AM ----------

YAY!!! It works now!! THanks radoulov!! I have been looking at this script for 2 days straight trying to figure it out!!

Thanks!
Ben
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. 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

8. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: nurani
2 Replies

9. Shell Programming and Scripting

Perl Script Syntax error in version 4

Hi , I use the following simple perl script to find the yesterday time perl -e ' use POSIX(strftime); print POSIX::strftime("%a %b %e %H:%M:%S %Y", localtime(time-86400*$ARGV))' 1 However in the perl version 4 , it gives me the following error : Do the perl version 4 does not support... (4 Replies)
Discussion started by: youareapkman
4 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