Hi,
I'm totally new to perl and have a question:
I would like to import a textfile into a mysql db, using mysqlimport. The problem I have is the badly formated text and I'm wondering if perl could help me to parse the file and prepare it for mysqlimport.
The file contains x lines of information, whereas every single line represents a row in the db.
Every line -can- contain up to 42 different tags and for every tag there is exactly one value.
The problem is the -can-. If every line would always contain -all- tags in always the same order then I could easily import it into mysql.
Given conditions:
- Every of the 42 tags is unique (mi, mo, ti...)
- A tag only can exist once in a line
- A tag always has an attributed value -> (mi=12345)
- tag&values are terminated by a '/'
Here's an example of one single line:
(12)pc=+12345678987/(6)mi=281445/ti=0/po=23/no=0/(12)cg=+12345678987/(5)ni=relay/ty=12/it=5/et=1/(12)de=+98765432198/sz=98/(25)id=1050566425245192168207130/ds
=19700101T000030Z/dt=20030417T080025Z/st=20030417T075955Z/ex=20030424T075955Z/mp=1/mc=1/(10)mo=text/plain/(6)gi=281445/nn=1/(36)in=My System/(10)rt=MRSRrecord/fw=0/(1)ac=0/pm=2/ed=6/(3)oi=MM1/(3)ii=MM1/
The values in () can be ignored. They do not have to be parsed.
The result after parsing of a line should be like:
+12345678987,281445,0,23,0,+12345678987,relay,12,5,1,+98765432198, 98,1050566425245192168207130...,MM1,MM1
Since I need to match fieldnames from columns in mysql the missing tags should be inserted as well containing the value "0".
So the perl script should be able to check every single line, parse the line and add the missing tags to the formatted output.
Can anybody follow me? And is this possible to solve with perl?
/Wali
I'm totally new to perl and have a question:
I would like to import a textfile into a mysql db, using mysqlimport. The problem I have is the badly formated text and I'm wondering if perl could help me to parse the file and prepare it for mysqlimport.
The file contains x lines of information, whereas every single line represents a row in the db.
Every line -can- contain up to 42 different tags and for every tag there is exactly one value.
The problem is the -can-. If every line would always contain -all- tags in always the same order then I could easily import it into mysql.
Given conditions:
- Every of the 42 tags is unique (mi, mo, ti...)
- A tag only can exist once in a line
- A tag always has an attributed value -> (mi=12345)
- tag&values are terminated by a '/'
Here's an example of one single line:
(12)pc=+12345678987/(6)mi=281445/ti=0/po=23/no=0/(12)cg=+12345678987/(5)ni=relay/ty=12/it=5/et=1/(12)de=+98765432198/sz=98/(25)id=1050566425245192168207130/ds
=19700101T000030Z/dt=20030417T080025Z/st=20030417T075955Z/ex=20030424T075955Z/mp=1/mc=1/(10)mo=text/plain/(6)gi=281445/nn=1/(36)in=My System/(10)rt=MRSRrecord/fw=0/(1)ac=0/pm=2/ed=6/(3)oi=MM1/(3)ii=MM1/
The values in () can be ignored. They do not have to be parsed.
The result after parsing of a line should be like:
+12345678987,281445,0,23,0,+12345678987,relay,12,5,1,+98765432198, 98,1050566425245192168207130...,MM1,MM1
Since I need to match fieldnames from columns in mysql the missing tags should be inserted as well containing the value "0".
So the perl script should be able to check every single line, parse the line and add the missing tags to the formatted output.
Can anybody follow me? And is this possible to solve with perl?
/Wali