For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2005 > lwp-download









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 lwp-download
Benjamin Jeeves

2005-02-25, 3:57 pm

Hi all

I have a perl program that I have developed that stores some numbers in a
mysql databases. But I need to make the script go to a web site download a
CSV file and the process the data in that file. I have try lwp-download by
using system("lwp-download the URL"); but once it has download the file it
will end the script and will not process the new file

can any body help me please.

Thank you

Ben
Charles K. Clarkson

2005-02-25, 3:57 pm

Benjamin Jeeves <benjamin@benjamin76.plus.com> wrote:

: I have a perl program that I have developed that stores some
: numbers in a mysql databases. But I need to make the script go
: to a web site download a CSV file and the process the data in
: that file. I have try lwp-download by using
: system("lwp-download the URL"); but once it has download the
: file it will end the script and will not process the new file
:
: can any body help me please.

Avoid creating perl solutions which depend on external
commands. External commands should be a last resort unless you
are deliberately scripting to create a batch file of some kind.


Use the LWP modules instead of a system command.
LWP::Simple will probably get you what you need. Look for the
"get" function in the docs. Also checkout the lwpcook and lwptut
docs.



HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328

Benjamin Jeeves

2005-02-25, 3:57 pm

Hi

I have now used the code below to download the CSV file which it does but the
rest of the script does not get executed e.g. to open the file and read the
data and place it in to it databases are ideas why?

use LWP::Simple;

$url = "web-server here";
$file = "/home/filename.csv";

$content = getstore($url,$file);

more code here which does not run

Thank you

Ben
On Friday 25 February 2005 15:24, Charles K. Clarkson wrote:
> Benjamin Jeeves <benjamin@benjamin76.plus.com> wrote:
> : I have a perl program that I have developed that stores some
> : numbers in a mysql databases. But I need to make the script go
> : to a web site download a CSV file and the process the data in
> : that file. I have try lwp-download by using
> : system("lwp-download the URL"); but once it has download the
> : file it will end the script and will not process the new file
> :
> : can any body help me please.
>
> Avoid creating perl solutions which depend on external
> commands. External commands should be a last resort unless you
> are deliberately scripting to create a batch file of some kind.
>
>
> Use the LWP modules instead of a system command.
> LWP::Simple will probably get you what you need. Look for the
> "get" function in the docs. Also checkout the lwpcook and lwptut
> docs.
>
>
>
> HTH,
>
> Charles K. Clarkson
> --
> Mobile Homes Specialist
> 254 968-8328

Benjamin Jeeves

2005-02-25, 3:57 pm

It is ok now I have it working thank you

Ben
On Friday 25 February 2005 15:24, Charles K. Clarkson wrote:
> Benjamin Jeeves <benjamin@benjamin76.plus.com> wrote:
> : I have a perl program that I have developed that stores some
> : numbers in a mysql databases. But I need to make the script go
> : to a web site download a CSV file and the process the data in
> : that file. I have try lwp-download by using
> : system("lwp-download the URL"); but once it has download the
> : file it will end the script and will not process the new file
> :
> : can any body help me please.
>
> Avoid creating perl solutions which depend on external
> commands. External commands should be a last resort unless you
> are deliberately scripting to create a batch file of some kind.
>
>
> Use the LWP modules instead of a system command.
> LWP::Simple will probably get you what you need. Look for the
> "get" function in the docs. Also checkout the lwpcook and lwptut
> docs.
>
>
>
> HTH,
>
> Charles K. Clarkson
> --
> Mobile Homes Specialist
> 254 968-8328

Todd W

2005-02-25, 8:55 pm


"Benjamin Jeeves" <benjamin@benjamin76.plus.com> wrote in message
news:200502251612.59906.benjamin@benjamin76.plus.com...
> Hi
>
> I have now used the code below to download the CSV file which it does but

the
> rest of the script does not get executed e.g. to open the file and read

the
> data and place it in to it databases are ideas why?
>
> use LWP::Simple;
>
> $url = "web-server here";
> $file = "/home/filename.csv";
>
> $content = getstore($url,$file);
>
> more code here which does not run
>


Do you have to store the file to disk? Why not just keep it in memory?

use DBI;
use Text::CSV;
use LWP::Simple;

$dbh = DBI->connect( ... );
$sth = $dbh->prepare( 'INSERT INTO table VALUES (?, ?, ...)' )
foreach my $line ( split(/\n/, get( $url )) ) {
# split record in to fields... see Text::CSV
$sth->execute( @splitted_stuff );
}

Todd W.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com