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: Perl Programming Help: Intermediate:
perl script to read csv file and create mysql tables

 



jeffersno1
Novice

Sep 21, 2018, 12:29 PM

Post #1 of 2 (980 views)
perl script to read csv file and create mysql tables Can't Post

Evening all,

Hoping someone can help me here... I'm a fan of perl, but i'm not good at it and i know when to ask for help...

I've got a daily config file that is 240k lines of text in csv format. i want to insert all the data into a mysql database so i can compare the config files and run mysql queries on them...

To start with 47 different types of lines where the first column is what i want the mysql table to be called, for example:

ADD QUOTA:QUOTANAME="10GBQUOTA",QUOTAMANAGER=QMAN,QUOTACLASS=Volume,ACCUMULATIONTYPE=Period,TYPE=Service Level,ISONEOFF=No,MKSTRING="1234",QUOTAVALUE=1024000000,QUOTASLICETYPE=Value,QUOTASLICEVALUE=256000,EDR=NotRecord,GRPQUOTAALLOCMETHOD=Default Allocation,BILLINGCYCLEMODE=Billing Cycle,BILLINGCYCLETIME=23&59&59,BALANCERESETMETHOD=Reset,BALANCEALLOCMODE=Default,LEVEL1=80,USERSTATUSAUTORESET=No,SUPPORTQTATRANSFER=No,RELATION=AND;

ADD CONDITIONGROUP:CONDITIONGROUPNAME="123_i_allowance_volume",RELATION=AND;

ADD CONDITION:CONDITIONGROUPNAME="123_i_allowance_volume",CONDITIONNAME="123_i_allowance_volume",OBJECTATTRIBUTE="Quota.QuotaStatus",OPERATOR=Equal,RIGHTVALUETYPE=Value,RIGHTVALUE="Level1";

ADD CT:CUSTOMERTYPEREF="CUSTOMERTYPE1CT",ROAMINGSTATUS=Local,CUSTOMERTYPE="CUSTOMERTYPE1",CTPRIORITY=12345,DESCRIPTION="111",CONGRPRELATION=AND;



MySQL table names:
QUOTA:QUOTANAME
CONDITIONGROUP:CONDITIONGROUPNAME
CONDITION:CONDITIONGROUPNAME
CT:CUSTOMERTYPEREF

Can someone help me here and advise on best way to script this?

I need a script that can open the file, not sure if i should be creating an array or hash, how to grab the data to create a mysql table?

Any help greatly appreciated

Thanks
Jeffers


FishMonger
Veteran / Moderator

Sep 21, 2018, 6:04 PM

Post #2 of 2 (974 views)
Re: [jeffersno1] perl script to read csv file and create mysql tables [In reply to] Can't Post

We're not a free code writing service but we can help you troubleshoot your code.

What have you tried?

The sample lines from your csv file doesn't have the proper info needed to create tables. You will need to create your database schema before parsing this csv file. The colon is not an allowed character in table names, so you'll need to adjust the table names.

My first thought regarding parsing the csv file is to put the data into a hash.

 
 


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

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