Hi, I am new to perl, I really didn't have time to go through perl nicely and was assigned this task for completion. I have written this code with all my broken knowledge and I am aware it must be horrible.
Please have a look if you can help. If that's too much, pointing out errors will work out fine for me, I'll rectify it myself.
I will really love some help rather than criticism

I have an input csv file with 18 column referred as Column A to Column R. I need a formatted output file and error file on based on these conditions:
1. Replace + and = in column D by blank
2. Move all rows to error files which has BC entries in column O
3. Delete rows for 0000,1111,2222 in column A
4. If column A has 2323 column O should only have AA, if not move to error
5. If column A has 1212, change it to 'a'.. If 2121 then change to aa and if 3131 change to ba
6. If column A has 6767,9898 or 5656 and column D contains '09 09' type 'AA' in column G.
The written code has lot of syntax and logical errors.
Many of them are because of wrong declaration, use of strict etc.
But if not, there are logical errors which leads to printing only one row in output file and no result in error file.
I am also facing difficulties in parsing csv line by line and seperating fields in commas. Please have a look if you can help.
Many many thanks!

# !/user/bin/perl use strict; use file :: basename use file :: copy #command line arguments my #input1=$ARGV[0] my #string; # array to store extracted dields my @records; my @fieldvalues; # assign paths for output files my $destinationapth="D/perl/output/"; my $destination="$destinationpath."OutputFile.txt"; my $destination1="$destinationpath."Error.txt"; open(IN, ">$destination"); opne(IN_Err,">$destination1"); open(DATA1,"<$input1"); my $a=0; while(<DATA1>) { $String="."; $String=$_; @records=Split(/\n/,$String); foreach $fieldvalues(@records) { @fieldvalues=split(/,/,$String); #to split columns from each r +ow in csv file foreach my $element(@fieldvalues) { # to remove linebreaks & whitespaces $element= ~s/\r|\n//g; } # Deleting values not needed in output if ($fieldvalues[0] eq '1111' || $fieldvalues[0] eq '2222' || +$fieldvalues[0] eq '0000') { #do nothing } else { #checking COL A for 2323 & column O except than AA if($fieldvalues[0] eq '2323' && $fieldvalues[14] ne 'AA') { #move to err file PRINT IN_Err ("@records\n"); } #replace "+/=" with " "(space) in col D $ fieldvalues[3] = ~s/[+=]/ /g; #replacing Col A values if($fieldvalues[0] eq '1212') { $fieldvalues[0] ='a'; } if($fieldvalues[0] eq '2121') { $fieldvalues[0] ='aa'; } if($fieldvalues[0] eq '3131') { $fieldvalues[0] ='ba'; } } # if for specific COL A values, column D contains specific tex +t, replacing column G value if ($fieldvalues[0] eq '9898' || $fieldvalues[0] eq '6767' || +$fieldvalues[0] eq '5656') { if(index($fieldvalues[3], '09 09')!==-1) { $fieldvalues[6]='AA; } #printing in formatted file print IN ("@records\n"); } } } Close (DATA);

In reply to Perl: Syntax Errors, Help Needed by Novice_Monk23

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.