Please help me understand errors in perl program


 
Thread Tools Search this Thread
Top Forums Programming Please help me understand errors in perl program
# 1  
Old 01-12-2015
Please help me understand errors in perl program

co
Code:
#! /usr/bin/perl

use strict;
use warnings;
use diagnostics;

my $amount=""; my $bain; ; my $code="";
my $date;my $day;my $line; my $mo; my $LNUM = 0;
my $xyz=""; my $yr;

$yr = 2015;
my $F; my @F;
while (<>) {
    chop;
    ++$LNUM;
    @F = split(';');
    if ( $F[0] eq "Date" ) { next; }
    elsif ( $xyz eq "" ) { next; }
    else { 
    foreach (@F) {
        $date   = $F[0];
        $code   = $F[1];
    } 
    } elsif ($LNUM==3) {  #ERROR 1
        $line ="EA:\n";
    $line+="bain+\t"+$bain+"\t";
    print $line."\n";
    } elsif ( $yr != 0 ) { #ERROR 2
    printf( "%02d %02d %2s\n", $mo,$day,$code )."\n";
    print $line."\n";
    }  else { #ERROR 3
    print $line."\n";
  }
}

de

---------- Post updated at 05:12 PM ---------- Previous update was at 05:04 PM ----------

Code:
perl -c traccTest.pl infile outfile produced:
syntax error at line 34 near "} else if"
syntax error at line 38 near "} else if"
syntax error at line 41 near "}"

I cannot find any obvious pair of braces that seems wrong.
Any help would be appreciated
hpk

Last edited by Don Cragun; 01-12-2015 at 09:33 PM.. Reason: Add CODE tags.
# 2  
Old 01-12-2015
Without a sample data file to test this with it's just a hard read.

Try starting a new if block after the else above, which ends the first if block:
} if ($LNUM==3) { #ERROR 1 # change elsif
and
printf( "%02d %02d %2s\n", $mo,$day,$code ); # drop the ."\n"
If you need a newline there add it to the format string "%02d %02d %2s\n\n"

Last edited by ongoto; 01-12-2015 at 09:48 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to understand how the line in perl program works as shell commend

I have a file with two line, one is header, the other actual value: TYPCD|ETID2|ETID|LEG ID|PTYP|PTYP SUB|TRD STATUS|CXL REASON|CACT|CACTNM|ENCD|ENC D NM|TRDR|ASDT|TRDT|MTDT|STDT|LS|SECID|SECID TYP|SECNM|PAR|STCC|MARKET PRICE|DIS MARKET PRICE|MARKET PRICE CURRENCY|SRC OF SETTLEMENT... (2 Replies)
Discussion started by: digioleg54
2 Replies

2. Shell Programming and Scripting

Trying to understand perl error

I am trying to begin to troubleshoot this perl error that I keep getting, yet I get output is produced. The error is Use of uninitialized value in join or string line 175, <MANNO> line 7138 and below is line 175: I am not too sure what the error is but since not every line has an error on it, I... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. Programming

Need program to continue even when encountering errors

I am writing a program, and want to have the option for the program to continue execution even should things go wrong. I use an option --ignore-errors. The problem is what I do when an error occurs, set the values to zero, or fill them up with some values, for example taken from a simple unit... (3 Replies)
Discussion started by: kristinu
3 Replies

4. Programming

Cannot understand the C errors

I have this peice of code I was hoping someone could look at. I use valgrind ./a.out to test it and it comes up with errors but none that I can understand. Maybe someone here could help me. The code is here: Neo - Pastbin Link Removed - Do Not Use Pastebin in these Forums (12 Replies)
Discussion started by: Errigour
12 Replies

5. Homework & Coursework Questions

program to find and print a Fibonacci sequence of numbers. --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: I am trying to convert a C language program over to Sparc Assembley and I am getting Undefined first referenced... (4 Replies)
Discussion started by: kenjiro310
4 Replies

6. Shell Programming and Scripting

Help me understand the Perl script..

#!/usr/bin/perl use strict; use warnings; print "Demo of array slicing \n"; my @abc="a b c d e f g h i j k l m n o p q r s t u v w x y z"; my @a=@abc; my @random=@abc; my @comp=@abc; my @comp1=(@abc,"Hello",@abc); print "abc is @abc \n"; print "a is @a \n"; print "random is @random \n";... (1 Reply)
Discussion started by: dnam9917
1 Replies

7. Shell Programming and Scripting

Perl syntax that I don't understand.

I'm just trying to confirm that I understand someone's code correctly. If someone has code that says: $foo ||= mysub(); I'm assuming that it means if $foo is nothing or undef, then assign it some value via mysub(). If I'm wrong on this, please let me know. Also, what's the difference... (4 Replies)
Discussion started by: mrwatkin
4 Replies

8. AIX

How to read or understand errors in errpt

Hello, after upgrading the memory to 96GB & 6 Dual Processor for P 550 ( and still not applied the parameters which some experienced posters said in post https://www.unix.com/aix/141835-oracle-database-running-slow-aix-nmon-topas-6.html ) I am getting system dumps. How to understand and... (1 Reply)
Discussion started by: filosophizer
1 Replies

9. Shell Programming and Scripting

Script to capture date/time in seconds in PERL... Cant understand errors

I'm Using this script to find the time of a file. I'm very much new to PERL and found this script posted by some one on this forum. It runs perfectly fine, just that it gives me following errors with the accurate output as well. I jus want the output to be stored in another file so that i can... (0 Replies)
Discussion started by: bankimmehta
0 Replies

10. Shell Programming and Scripting

perl regexp error , I cant understand what is wrong

perl regexp error , I cant understand what is wrong Hello all I have simple perl regexp that is searching for pattern in string and replace it with the same string + addition string here is what I have : my $rec = q| new Array("Attributes Management" ... (4 Replies)
Discussion started by: umen
4 Replies
Login or Register to Ask a Question