how to read a file which is lying on any server ?

Hi ! How can I read a file which is not lying on my server ? The user types in the url and I want to open this file and save it in an array of lines.

How to do this  (code) ?

regards
ItsMe
ItsMeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
maxkirConnect With a Mentor Commented:
use LWP::Simple;

# Get file content
$content = get('http://www.anyserver.de/whatever.txt');

# split content
@lines = split(/\n/, $content);

getprint gets and prints file content.

regards,
KIR
0
 
ItsMeAuthor Commented:
ps: I want to do this with perl.
0
 
shiversCommented:
you will need to use a sockets library for Perl - which will let you make TCP/IP socket connections to other servers, the use these connections to retrieve files from the other machines.

The protocol to be used depends on the URL - i.e. http or ftp
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
ItsMeAuthor Commented:
it will be always a link like http://www.anyserver.de/any.txt
Isn't it easyer to manage that ? I just want to read the file. I found a code which works (but there are strange ascii's in it):

use LWP::Simple;
$rc = getprint('http://www.anyserver.de/whatever.txt');
print status_message($rc);

PS: I'm new in Perl and don't know how to manage this problem. It would be cool to have some source.

regards
ItsMe
0
 
ozoCommented:
What do you mean there are strange ascii's in it?
0
 
ItsMeAuthor Commented:
If start the cgi my browser asks me for saving the file. If I saveit it includes I think line breaks at the end of each file. how can I read the file in an array of lines ?
perhaps by splitting with <cr><lf> as divider ? how do I write this in perl ?

@lines = split.....

regards
ItsMe

PS: Can you explain what the code above does ? (getprint ...)
0
All Courses

From novice to tech pro — start learning today.