Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Parse csv file

New User

Nov 4, 2012, 7:48 AM

Views: 10086
Parse csv file

I am looking for a program to parse info from a csv file.

Those fields are:
title text,
reference text not null primary key,
location text,
hours text,
wage text,
work_pattern text,
employer text,
employer_ref text,
pension text,
duration char, -- P or T or NULL
closing_date date,
description text,
apply text,
added date not null default current_date,
office_code char(3)

I need a program that would check the location , if the location is

"manchester" , output location and also output the information contained
in the apply field.

The location also contains a postcode , and I would like to have a total

of all the number of postcodes , eg

M1 5(occurances)
M4 7(occurances)
M21 3(occurances).

I am unfortunately very new to perl.

Any help in finding a program that does this would be very helpful.
Thanks in advance.

Veteran / Moderator

Nov 4, 2012, 9:55 AM

Views: 10083
Re: [angeeze] Parse csv file

You might want to look at one of the CPAN CSV modules, such as this one for example:


but I am not sure whether it will work for you, because your file does not seem to be a regular CSV file. If not, you'll have to parse the file yourself, which doesn't seem to be very complicated, but you'll need at least a basic comprehension of Perl.


Nov 5, 2012, 9:23 PM

Views: 10056
Re: [angeeze] Parse csv file

Parsing of a csv file can be as simple as split-on-comma or as complex as a module will allow. The choice depends on the data. If you expect any real help, we will need a reasonably long sample of realistic (preferably real) data. I already have a few questions which could be answered from that data.

The location field is clearly very important. The concept is probably perfectly clear to you. I think I can guess what a 'postcode' is, but certainly not well enough to parse the location field.

duration char, -- P or T or NULL

One field or two?

Can any of your text contain commas? If so, how are they escaped?
Good Luck,

New User

Nov 6, 2012, 10:33 AM

Views: 10042
Re: [BillKSmith] Parse csv file

Thank you all so much for taking the time to reply , your time and help is appreciated. I am attaching a sample data set. I have about 20 mins spare everyday to learn perl , slowly but surely....If anyone has any tips on the sections of perl I should be learning to make my quest easier I would be forever grateful. I require the output as a simple txt file. I am abroad and am returning to the UK in a hurry and need the info for job hunting. Thanks again for all replies.

Thanks Laurent and thanks BillSmile
Attachments: sample.csv (31.8 KB)


Nov 6, 2012, 8:00 PM

Views: 10004
Re: [angeeze] Parse csv file

Processing this data is beyound my skill level. I have already found the following problems.

  • Header record does not match your posted specification.

  • No record appears to conform to either one

  • Fields with similiar data are not always in the same field position

  • We only need two fields (location and apply). Location is always in the third field, but the apply field cannot be identified by position. Its content is free form so there is little hope of identifying it lexically.

  • The record format is much to complex to break into fields with split. The module which Laurent suggested fails with no useful information. There probably is a module solution, but I will not look for it because I have already wasted too much time on what appears to be a hopless task.
    Good Luck,