Link to home
Start Free TrialLog in
Avatar of Tech_20
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
SOLUTION
Avatar of FishMonger
FishMonger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tech_20
Tech_20

ASKER

Thanks. I tried this script and I get this error (referring to the sample .csv files to parse).

______________

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.
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.
Avatar of Tech_20

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.
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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tech_20

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