Hi all,

I am in a situation where I don't know much PERL/CGI, but am frantically reading through the learn Perl/learnCGI in 24 hour books. I just got done programing in dbase for some climatology work and now have to switch gears quickly.

My mission: to read in a (comma-delimited)web file with no extension:
http://147.241.74.132/cgi-bin/model/fddasites.csv?RANGE=crtc&GLOB=CS8&PATH=images/rtfdda/&BIAS=OFF
The problem is, that I want to skip down 14-16 lines to get to the first line of data.

What is the easiest way to read in the lines of data, into an array?

A friend sent me this link: CGISCRIPTER

Is this along the lines of what I need? i will be placing simple (~50)Excel line equations probably into an array as well to perform calculations with the read in values. I will output the answers to a simple HTMl page.

HELP! I don't know much in the realm of CGI scripting, but I have been learning MySQL. I read in one message board that you can use "LOAD DATA INFILE 'C:\Documents and Settings\d~1\Desktop\test.csv' INTO TABLE x; " or something along those lines? Could MySQL be used or is just faster just to have PERL do all the reading, writing and arithmetic?

Anyways, thanks to anyone who would lend a helping thought,
Dave

PS- In the perl books, where should I concentrate my reading? using the "OPEN" command?

Recommended Answers

All 5 Replies

You can certainly use the open() command to read a file, any file, as long as your script has permission to open the file. We will assume it does.

There are perl modules for reading CSV files too:

http://search.cpan.org/~hmbrand/Text-CSV_XS-0.31/CSV_XS.pm

This gets into the "you need to install the module" discussion though. But if you can tackle the installation problem the above module works well.

You may very well be able to use MySQL but you need to ask on the MySQL forum.

Hi Kevin,

thanks for your thoughts. I have successfully read in the file (that I saved to my pc), but when I try to place the URL inside the quotes I get errors.

To retrieve the file, do I have to use some sort of "use HTML::LinkExtor;" ? LWP?

I don't understand what you are asking. Post your perl code.

Are you trying to use the open() function to read a file on another server? That will not work.

Hi all,

I am in a situation where I don't know much PERL/CGI, but am frantically reading through the learn Perl/learnCGI in 24 hour books. I just got done programing in dbase for some climatology work and now have to switch gears quickly.

My mission: to read in a (comma-delimited)web file with no extension:
http://147.241.74.132/cgi-bin/model/fddasites.csv?RANGE=crtc&GLOB=CS8&PATH=images/rtfdda/&BIAS=OFF
The problem is, that I want to skip down 14-16 lines to get to the first line of data.

What is the easiest way to read in the lines of data, into an array?

A friend sent me this link: CGISCRIPTER

Is this along the lines of what I need? i will be placing simple (~50)Excel line equations probably into an array as well to perform calculations with the read in values. I will output the answers to a simple HTMl page.

HELP! I don't know much in the realm of CGI scripting, but I have been learning MySQL. I read in one message board that you can use "LOAD DATA INFILE 'C:\Documents and Settings\d~1\Desktop\test.csv' INTO TABLE x; " or something along those lines? Could MySQL be used or is just faster just to have PERL do all the reading, writing and arithmetic?

Anyways, thanks to anyone who would lend a helping thought,
Dave

PS- In the perl books, where should I concentrate my reading? using the "OPEN" command?

First I must warn you - you can't 'learn' any programming language in 24 hours. And forget about using MySQL for solving your problem. It's enough you have one learning curve to learn.

To address your immediate question 'to skip down 14-16 lines', Perl has a special variable called $. - that is a dollar sign with a dot immediately following it.

It is the current line counter, and is used something like this:

open IN ,'<', $somefile or die "Can't open $somefile: $!\n"; # ALWAYS check open result
while (defined ($line = <IN>))
{
print "Current line = $.\n";
}
close IN or die "Can't close $somefile: $!\n"; # and check the close result

So, in your case you want to read the file until $. equals 14 or 16. I leave that as an exercise for you.

You will have to provide more details to determine whether to read 14, 15, or 16 lines.

Thanks for your help everyone. It pointed me to some new options in the coding. I didn't see the last post by trudge until now. I ended up ingesting the webfile into an array and then using:
@temparray= split/([,' '])/, $hours[$i];

which tells it whenever there is a comma and/or a space then split it. It took me forever to find this code, but it works great!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.