CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



angeeze
New User

Nov 4, 2012, 7:48 AM

Post #1 of 5 (4144 views)
Parse csv file Can't Post

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.


Laurent_R
Veteran / Moderator

Nov 4, 2012, 9:55 AM

Post #2 of 5 (4141 views)
Re: [angeeze] Parse csv file [In reply to] Can't Post

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

http://search.cpan.org/~tmtm/Text-CSV-Simple-1.00/lib/Text/CSV/Simple.pm

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.


BillKSmith
Veteran

Nov 5, 2012, 9:23 PM

Post #3 of 5 (4114 views)
Re: [angeeze] Parse csv file [In reply to] Can't Post

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.


Quote
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,
Bill


angeeze
New User

Nov 6, 2012, 10:33 AM

Post #4 of 5 (4100 views)
Re: [BillKSmith] Parse csv file [In reply to] Can't Post

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)


BillKSmith
Veteran

Nov 6, 2012, 8:00 PM

Post #5 of 5 (4062 views)
Re: [angeeze] Parse csv file [In reply to] Can't Post

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,
    Bill

  •  
     


    Search for (options) Powered by Gossamer Forum v.1.2.0

    Web Applications & Managed Hosting Powered by Gossamer Threads
    Visit our Mailing List Archives