#!opt/local/bin/perl5

use strict;
use Spreadsheet::ParseExcel;
use XLSX.pm;
my $oExcel = new Spreadsheet::ParseExcel;

die "You must provide a filename to $0 to be parsed as an Excel file" unless @ARGV;

my $oBook = $oExcel->Parse($ARGV[0]);
my($iR, $iC, $oWkS, $oWkC);
print "FILE  :", $oBook->{File} , "\n";
print "COUNT :", $oBook->{SheetCount} , "\n";

print "AUTHOR:", $oBook->{Author} , "\n"
 if defined $oBook->{Author};

for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++)
{
 $oWkS = $oBook->{Worksheet}[$iSheet];
 print "--------- SHEET:", $oWkS->{Name}, "\n";
 for(my $iR = $oWkS->{MinRow} ;
     defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ;
     $iR++)
 {
  for(my $iC = $oWkS->{MinCol} ;
      defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol} ;
      $iC++)
  {
   $oWkC = $oWkS->{Cells}[$iR][$iC];
   print "( $iR , $iC ) =>", $oWkC->Value, "\n" if($oWkC);
  }
 }


I keep getting this error
syntax error in file excel_perl.pl at line 3, next 2 tokens "use strict"
and so on...
any help?

Recommended Answers

All 4 Replies

Hi voidyman!

I'm not sure how you got those fonts in here, but it sure makes your post hard to read!

A quick check of your script with 'perl -c' shows that the script (at least what you've pasted here) is missing a curly bracket at the end of the file (for that big "for(my $iSheet..." loop).

Another thing that *might* be an issues is the 'use XLSX.pm;' line. If that's a module you're including locally, try it without the '.pm' extension (use XLSX;)

I hope this helps!

It helped . This problem Went away. Figures I do not have all my perl modules installed. Thanks Gromit.Wallace is grateful :)
And sorry abt the font. Copied from vi editor.

I kept gettin the errors when i tried to run my perl script
syntax error in file /home/common/bin/NEL_MailHouseKeeper.pl at line 15, next 2 tokens "my $PATH "
syntax error in file /home/common/bin/NEL_MailHouseKeeper.pl at line 134, next 2 tokens "my $FLAG_PRINT "

#!/usr/contrib/bin/perl

my $PATH = "/var/mail";
my $SHOWPATH = "/usr/bin/pwd";
my $RENAME = "/usr/bin/mv";
my $SWITCHPATH = "/usr/bin/cd";
my $COPY = "/usr/bin/cp";
my $DELETE = "/usr/bin/rm";
my $GZIP = "/usr/contrib/bin/gzip";
my $DATE = `/usr/bin/date '+%d_%b_%Y'`;
my $SENDMAIL = "/sbin/init.d/sendmail";
my $SLEEP = "/usr/bin/sleep";
my $MAILER = "/usr/bin/mailx";
my $EMAIL_SUBJECT = "";
my $EMAIL_C755 = "c755mnt";
my $EMAIL_PASS = "/home/common/email/EMAIL_MAIL_HOUSEKEEPER_PASS";
my $EMAIL_FAIL = "/home/common/email/EMAIL_MAIL_HOUSEKEEPER_FAIL"; 
my $EMAIL_ABORT = "/home/common/email/EMAIL_MAIL_HOUSEKEEPER_ABORT";

my $RETURN = 0;
my $CHECKBIT => 0;
my $BASEFILE = $ARGV[0];
my $DUPFILE = $ARGV[0]."_Copy";
my $TEMPFILE = $BASEFILE."_".${DATE};
my $TEMPFILE2 = $BASEFILE."_tmp";
my $LINE_BUFFER = "";
my $BUFFER = "";
my $TOTAL_MAILS = 0;
my $MAILS_TO_ARCHIVE = 0;
my $THRESHOLD = 10;
my $COUNTER = 0;


        #(0) <<START>>
        my $date = `/usr/bin/date`;
        print "Starting NEL_MAILHOUSEKEEPER script at $date \n";

        #(1) Stop sendmail
        $RETURN = system "$SENDMAIL stop";
        if ($RETURN == $CHECKBIT)
        {
            print "STEP 1: sendmail is stopped successfully. \n";
        }
        else
        {
            print "STEP 1: sendmail cannot be stopped ! \n";
            print "The task is aborted ! \n";
            $date = `/usr/bin/date`;
            print "Exiting at $date !!! \n";
            exit;
        }

        #(2) Goto working directory
        $RETURN = system "$SWITCHPATH $PATH";
        if ($RETURN == $CHECKBIT)
        {
            print "STEP 2: Path is switched to `$SHOWPATH` successfully. \n";
        }
        else
        {
            print "STEP 2: Could not switch to $PATH ! \n";
        }

        #(3) Duplicate original file for processing
        $RETURN = system "$COPY -p $BASEFILE $DUPFILE";
        if ($RETURN == $CHECKBIT)
        {
            print "STEP 3: The original mail file is duplicated successfully for processing. \n";
        }
        else
        {
            print "STEP 3: Duplication of original mail file fails ! \n";
            print "The task is aborted ! \n";

            #Start sendmail
            $RETURN = system "$SENDMAIL start";
                        system ("$SLEEP 1");
                        if ($RETURN == $CHECKBIT)
                        {
                                print "sendmail is started successfully. \n";
                $date = `/usr/bin/date`; 
                print "Exiting at $date !!! \n";
                exit;
            }
            else
            {
                print "sendmail cannot be started ! ISCS Maintenance needs to manually start sendmail IMMEDIATELY ! \n";
                exit;
            }
        }

            #Count the total number of emails first
        open(FILE, "<$DUPFILE");
        while ($LINE_BUFFER = <FILE>)
        {
            if ($LINE_BUFFER =~ m/^From /)
                    {
                            $TOTAL_MAILS++;
                    }
        }
        close(FILE);
        print "Total mails found in $BASEFILE -> $TOTAL_MAILS\n";

        #(4) Begin Processing the mails
        print "STEP 4: Processing the mails now......\n";

        if ($TOTAL_MAILS > $THRESHOLD)
        {
            #Processing the old emails into 1 mail file and leaving last 10 emails into original mail file 

            $MAILS_TO_ARCHIVE = $TOTAL_MAILS - $THRESHOLD;
            print "Total old mails to archive -> $MAILS_TO_ARCHIVE\n";

            open(FILE1, "<$DUPFILE");
            open(FILE2, ">$TEMPFILE");
            open(FILE3, ">$TEMPFILE2");

            while ($BUFFER = <FILE1>)
            {
                if ($BUFFER =~ m/^From /)
                {
                    my ${FLAG_PRINT} = 1;
                    $COUNTER++;
                }

                if (($FLAG_PRINT = 1) && ($COUNTER <= $MAILS_TO_ARCHIVE))
                {
                    print FILE2 $BUFFER;
                }
                elsif (($FLAG_PRINT = 1) && ($COUNTER > $MAILS_TO_ARCHIVE) && ($COUNTER <= $TOTAL_MAILS))
                {
                    print FILE3 $BUFFER;
                }
            }
            close(FILE1);
            close(FILE2);
            close(FILE3);

            print "Processing of the mails is completed......\n";
        }
        else
        {
            #Remove the Duplicate file
            $RETURN = system "$DELETE $DUPFILE";
            if ($RETURN == $CHECKBIT)
            {
                print "Duplicate mail file is deleted successfully \n";
            }
            else
            {
                print "$DUPFILE cannot be deleted ! ISCS Maintenance needs to delete it manually ! \n";
            }

            if ($TOTAL_MAILS < $THRESHOLD)
            {
                print "Total mails found are less than the threshold mails (10) ! \n";
            }
            elsif ($TOTAL_MAILS == $THRESHOLD)
            {
                print "Total mails found are same as the threshold mails (10) ! \n";
            }   
            #Start sendmail
            $RETURN = system "$SENDMAIL start";
            system ("$SLEEP 1");
            if ($RETURN == $CHECKBIT)
            {
                print "sendmail is started successfully. \n";

                #Send email informing maintenance team that task is aborted
                $EMAIL_SUBJECT = '"AUTOMATION TASK: NEL_MailHouseKeeper.pl script run result -> ABORT"';
                system ("$MAILER -s $EMAIL_SUBJECT $EMAIL_C755 < $EMAIL_ABORT");

                $date = `/usr/bin/date`;
                print "Exiting now at $date ......\n";
                print "++++++++++++++++++++++++++++++++++++++++++++++\n";
                exit;
            }
            else
            {
                print "sendmail cannot be started ! ISCS maintenance needs to manually start sendmail IMMEDIATELY ! \n";
                exit;
            }
        }

        #(5) Archive the old emails in 1 mail file (e.g. nelprofile-fwc_<date>.gz)
        $RETURN = system "$GZIP -9 $TEMPFILE";
        system ("$SLEEP 2");
        if ($RETURN == $CHECKBIT)
        {
            print "STEP 5: $TEMPFILE is zipped successfully. \n";
        }
        else
        {
                        print "STEP 5: $TEMPFILE cannot be zipped ! ISCS Maintenance needs to gzip manually ! \n";
        }

        #(6) Rename TEMPFILE2 to BASEFILE (renaming the processed mail file back to original mail file)
        $RETURN = system "$RENAME $TEMPFILE2 $BASEFILE";
        if ($RETURN == $CHECKBIT)
        {
            print "STEP 6: $TEMPFILE2 is renamed to $BASEFILE successfully. \n";
        }
        else
        {
            print "STEP 6: $TEMPFILE2 cannot be renamed to $BASEFILE ! \n";

            #Start sendmail
            $RETURN = system ("$SENDMAIL start");
                    system ("$SLEEP 1");
                    if ($RETURN == $CHECKBIT)
                    {
                            print "sendmail is started successfully. \n";

                #Send email informing maintenance team that task has failed
                            $EMAIL_SUBJECT = '"AUTOMATION TASK: Please inform C755 Maint Team (Hotline: 6214 0674)"';
                            system ("$MAILER -s $EMAIL_SUBJECT $EMAIL_C755 < $EMAIL_FAIL");
                exit;
            }
            else
            {
                print "sendmail cannot be started ! ISCS Maintenance needs to manually start sendmail IMMEDIATELY ! \n";
                exit;   
            }
        }

        #(7) Remove the Duplicate file
        $RETURN = system ("$DELETE $DUPFILE");
        if ($RETURN == $CHECKBIT)
        {
            print "STEP 7: Duplicate mail file is deleted successfully. \n";
        }
        else
        {
            print "STEP 7: Cannot delete duplicate mail file ! ISCS Maintenance needs to delete it manually ! \n";
        }

        #Start sendmail
        $RETURN = system ("$SENDMAIL start");
        system ("$SLEEP 1");
        if ($RETURN == $CHECKBIT)
        {
            print "sendmail is started successfully. \n";

            $date = `/usr/bin/date`;
                    print "NEL_MAILHOUSEKEEPER script has completed at $date \n";
                    print "++++++++++++++++++++++++++++++++++++++++++++++\n";

            #Send email informing the operator that task is completed successfully
            $EMAIL_SUBJECT = '"AUTOMATION TASK: NEL_MailHouseKeeper.pl script run result -> SUCCESSFUL"';
                        system ("$MAILER -s $EMAIL_SUBJECT $BASEFILE < $EMAIL_PASS");
        }
        else
        {
            print "sendmail cannot be started ! ISCS Maintenance needs to manually start sendmail IMMEDIATELY ! \n";
        }   

James 79,

You are posting a new question under a solved trend. There is a every chance that your question would not be attended to. Because the trend already has a Solved mark.
So, Please start a new disussion instead.

Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.