FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Perl server referencing





Lukrasha
I've been learning perl for the past few months, and I keep seeing things referencing getting data and printing it with the content from outside servers (such as game server information) onto a web app. Does anyone know how you can take the information from the server and print it into an app?
friscofrankie
Lukrasha wrote:
I've been learning perl for the past few months, and I keep seeing things referencing getting data and printing it with the content from outside servers (such as game server information) onto a web app. Does anyone know how you can take the information from the server and print it into an app?

I few more specifics please.

Data from a server:

Is that:

Database data?
Environment data?
data stored in a file?
A sever under your control or just apublic server?
You wanna build a sort-of web-bot?

If you're not sure give us an idea of what it is you're tying to do.
There are several ways to do almost anythng in Perl. Having a bit more information would help
I might be able to help but wthout more info i really coldn't even try.
webapp
==================================
Consider the case when you need some information from other website. The simplest way to get it is to write the CGI script that connects to the other website and requests the document by HTTP request. Then you will be able to parse the document and get any information you need. For example currency exchange rate or leatest news from the other website.


The simplest way to do it is to use IO::Socket module. Here is the simple code with comments:

Tells Perl to use module
use IO::Socket;

Host address (or hostname) of website having needed document
my $host="webclass.ru";

Request string of simplest HTTP request to web server on distant host
We should write URL address of requested document here
my $getstring="GET http://webclass.ru/index.php3 HTTP/1.0\n\n";

Creating connection
Port number of web server = 80.
Protocol is tcp.
If connection couldn't be opened the execution dies here.
my $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => 80, Proto => 'tcp') or die "couldn't connect";

Sending HTTP request string to web server.
print $sock "$getstring";

Read the answer.
my $buf="";
while($line = <$sock>) {
$buf.=$line;
}

Close connection
close($sock);

Now you have requested document in the $buf variable
If you output it:
print $buf;
user will see complete document from the other website.
Most probably you will have to get a piece of data from the complete document. To do it you should write a regular expression of write a search procedure. Then you will be able to output the only information that you wan
========================================

The complete example with documentation is available at

http://www.webclass.ru/eng/Tutorials/Perl/...g_the_page.html
friscofrankie
As I said there are many ways to get something done in Perl.
If all you want to do is get a document from a site.
this is a bit shorter and more succint i think.
Code:

#!//usr/bin/perl

use LWP::Simple;

$url="http://whatever.wherever/whatyouwant.htm/php/pl/aspl";
$content = get($url)or die "could not get $url";

#now $content contains the entire file.

do something with("$content");


The above method works quite well also.
there are also modules available that will extract the file and mirror it to a file on your machne or modules that will extract the data you want from it.
If you want to gain access to another type of data let's hear about it. if you want to parse the data in the file or extract urls, tags or anyother data there are tools available to get the job done quickly.
You can search the CPAN repository at CPAN for LWP, URI, HTML or HTTP and find a lot of information how to use these modules. if you have trouble post 'em here. If you can get a copy of hte PERL Cookbook by O'reily, I highly recommend it.
As you can see there will be a few folks willing to help; each with a unique approach to the problem. Perl is extremely flexible, you can tailor the solutions to fit your needs.
Lukrasha
ok thanks guys... I'm writing a module to get information from my other websites and pull them into one client that allows me to access the info on all of my sites from one... I doubt it'll work, but what the heck, I'm still learning.
Related topics
writing COM components in Perl
"Forms To Go" create scripts in PHP, ASP and Perl
Path to Perl on server
Perl and Sendmail
problem with cgi perl script
What is the path to Perl?
Perl Script Internal Error
Help, I need LWP::Simple perl module!!
Perl modules in PHP?
Question about forms on websites?
Documentation for Perl scripts on server?
Scripting Language
Perl CGI 500 Internal Server Error
Best Server Software
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.