Tech_20
asked on
Using Perl to parse rows
I am having issues with parsing / eliminating certain rows in csv files using Perl. This attached Perl script (thanks to help from other EE members) parses the columns.
Now I need to eliminate rows complete pending on content in the 6th column so that the final result is listed in the sample (see begin and end sample .csv files).
Thanks for your help.
sample_perl.txt
begin_sample.csv
end_sample.csv
Now I need to eliminate rows complete pending on content in the 6th column so that the final result is listed in the sample (see begin and end sample .csv files).
Thanks for your help.
sample_perl.txt
begin_sample.csv
end_sample.csv
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The line numbers in the error messages don't line up with the code I posted.
Please post the updated code you ran.
The @col array only has 4 elements, unless you changed its assignment, so the obviously it's not going to have an index 6.
Please post the updated code you ran.
The @col array only has 4 elements, unless you changed its assignment, so the obviously it's not going to have an index 6.
ASKER
OK. I did and here is the result using the begin_sample.csv.
__________
Argument "BUILDING#" isn't numeric in numeric ge (>=) at ..filename... line 21, <$data> line 1.
Argument "BUILDING#" isn't numeric in numeric ge (>=) at ..filename... line 21, <$data> line 1.
Argument "BUILDING#" isn't numeric in numeric ge (>=) at ..filename... line 21, <$data> line 1.
Argument "BUILDING#" isn't numeric in numeric ge (>=) at ..filename... line 21, <$data> line 1.
__________
Argument "BUILDING#" isn't numeric in numeric ge (>=) at ..filename... line 21, <$data> line 1.
Argument "BUILDING#" isn't numeric in numeric ge (>=) at ..filename... line 21, <$data> line 1.
Argument "BUILDING#" isn't numeric in numeric ge (>=) at ..filename... line 21, <$data> line 1.
Argument "BUILDING#" isn't numeric in numeric ge (>=) at ..filename... line 21, <$data> line 1.
I was basing the building of the @col array on the fields you were extracting in the script, which, apparently doesn't match your csv file. Due to that inconsistency, I can't say for sure which fields to extract.
You just need to adjust the array slice to extract the desired fields and then adjust the array index in line 21 to reference the correct field.
You just need to adjust the array slice to extract the desired fields and then adjust the array index in line 21 to reference the correct field.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was able to take the previous blocks of code and create this (see attached) and it worked. Thanks a lot, FishMonger.
final_sample_perl.txt
final_sample_perl.txt
ASKER
______________
Use of uninitialized value $col[6] in numeric ge (>=) at ... line 24, <$data> line 1.
Can't call method "any" on an undefined value at ... line 27, <$data> line 1.
______________
I used $col[6] as the column with the zip codes to parse.