Jun 16, 2016, 4:11 AM
Post #1 of 3
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.
Help Needed :(
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 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!
use file :: basename
use file :: copy
#command line arguments
# array to store extracted dields
# assign paths for output files
@fieldvalues=split(/,/,$String); #to split columns from each row in csv file
foreach my $element(@fieldvalues)
# to remove linebreaks & whitespaces
# Deleting values not needed in output
if ($fieldvalues eq '1111' || $fieldvalues eq '2222' || $fieldvalues eq '0000')
#checking COL A for 2323 & column O except than AA
if($fieldvalues eq '2323' && $fieldvalues ne 'AA')
#move to err file
PRINT IN_Err ("@records\n");
#replace "+/=" with " "(space) in col D
$ fieldvalues = ~s/[+=]/ /g;
#replacing Col A values
if($fieldvalues eq '1212')
if($fieldvalues eq '2121')
if($fieldvalues eq '3131')
# if for specific COL A values, column D contains specific text, replacing column G value
if ($fieldvalues eq '9898' || $fieldvalues eq '6767' || $fieldvalues eq '5656')
if(index($fieldvalues, '09 09')!==-1)
#printing in formatted file
print IN ("@records\n");
(This post was edited by FishMonger on Jun 16, 2016, 7:44 AM)