jonam has asked for the wisdom of the Perl Monks concerning the following question:
I have an ods file which contains the data to insert into the database. How can I achieve this using perl?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: .ods file
by CountZero (Bishop) on Mar 14, 2009 at 08:21 UTC | |
A general procedure (applicable to all kinds of files) could be: CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James | [reply] [d/l] |
|
Re: .ods file
by targetsmart (Curate) on Mar 14, 2009 at 08:33 UTC | |
http://search.cpan.org/search?query=csv&mode=all Vivek -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet. | [reply] |
|
Re: .ods file
by leslie (Pilgrim) on Mar 14, 2009 at 10:53 UTC | |
This is my example program.. We have to export our .ods into .csv file. In this below example I have used that exported .csv file.
| [reply] [d/l] |
by CountZero (Bishop) on Mar 14, 2009 at 11:37 UTC | |
my @line=split(/,/,$_);See my comment above and repeat after me: I will never use a split on comma to deal with CSV-files. CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James | [reply] [d/l] [select] |
|
Re: .ods file
by vinoth.ree (Monsignor) on Mar 14, 2009 at 08:49 UTC | |
If your '.ods' file is a spreadsheet export this file to '.csv' file and open that file and use spite function and get data Try the following code for simple .ods file, your .ods file content will be in the "@arr" use it in the query.
| [reply] [d/l] |
by CountZero (Bishop) on Mar 14, 2009 at 11:32 UTC | |
What will happen if your file containes embedded delimiters? Through $f_line=~ s/\"//g; you have destroyed the quotes (why?) and then you naively split on the comma (which BTW does not have to be escaped in your regex). If you have embedded comma's in your fields you are now totally lost. Use any of the CSV modules, such as Text::CSV to do this "The Right Way". CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James | [reply] [d/l] [select] |