Home > Archive > PERL CGI Beginners > December 2005 > perl script to read a flat text file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
perl script to read a flat text file
|
|
| somegeek 2005-12-06, 7:55 am |
| Hi
I downloaded a database from one of the government sites pertaining to
some antenna registration. It contains a set of DAT files that has data
as follows:
CO|REG|A0000069|1000042|96980|T|32|40|31
.0|N|117631.0|97|8|29.0|W|349709.0
CO|REG|A0000097|1000064|96988|T|33|36|0.0|N|120960.0|85|50|0.0|W|309000.0
ofcourse it has tons of such columns in it.
I need to read in certain select columns of data from this 'I'
separated file onto a MySql database that I am going to create. This
database will have two two columns, say X1 and X2
I am going to read in (for instance) the following data:
A00000069 and A0000097 to X1 and
32 and 32 into X2
Is it possible to write a Perl Script that does this job of reading the
data in this fashion and populate the database.
I am new to Perl and any suggestions, pointers, etc is highly
appreciated
I thank you for your time, effort and patience
| |
| Paul Lalli 2005-12-06, 7:55 am |
| someg wrote:
> I downloaded a database from one of the government sites pertaining to
> some antenna registration. It contains a set of DAT files that has data
> as follows:
>
> CO|REG|A0000069|1000042|96980|T|32|40|31
.0|N|117631.0|97|8|29.0|W|349709.0
> CO|REG|A0000097|1000064|96988|T|33|36|0.0|N|120960.0|85|50|0.0|W|309000.0
>
> ofcourse it has tons of such columns in it.
>
> I need to read in certain select columns of data from this 'I'
> separated file
It looks | separated, not I separated, to me.
> onto a MySql database that I am going to create. This
> database will have two two columns, say X1 and X2
>
> I am going to read in (for instance) the following data:
> A00000069 and A0000097 to X1 and
> 32 and 32 into X2
>
> Is it possible to write a Perl Script that does this job of reading the
> data in this fashion and populate the database.
Yes.
> I am new to Perl and any suggestions, pointers, etc is highly
> appreciated
http://learn.perl.org
Once you've gotten Perl installed (if you use Unix, chances are it's
already available, otherwise visit http://www.activestate.com), you
have access to all Perl documentation using the `perldoc` command.
Start with:
perldoc perlintro
perldoc perlsyn
perldoc -f open
perldoc -f readline
perldoc -f split
Then investigate the DBI and DBD::mysql modules, both available from
http://search.cpan.org. And check out the DBI-specific information at
http://dbi.perl.org
Once you've made your attempt, feel free to post again asking for
assistance if your attempt doesn't work.
Paul Lalli
| |
| somegeek 2005-12-06, 6:55 pm |
| Thank you, Paul. I am going to try out this. Do you think the delimiter
symbol in the file is "|"(the pipe character on the keyboard) , and not
"I as in "ireland"?
And I can install the Perl for Windows, too, right?
| |
| Paul Lalli 2005-12-07, 7:55 am |
| someg wrote:
> Thank you, Paul. I am going to try out this. Do you think the delimiter
> symbol in the file is "|"(the pipe character on the keyboard) , and not
> "I as in "ireland"?
Correct. I would suggest using a font that distinguishes the two
characters. Courier and its family should do that job...
> And I can install the Perl for Windows, too, right?
Yes. As I said, vist http://www.activestate.com and follow the links
for "ActivePerl" (NOT "Active Perl Pro Studio")
Paul Lalli
| |
| somegeek 2005-12-16, 6:55 pm |
| Thank you, Paul..
I am going to try this out and let you know how it goes
ilango
|
|
|
|
|