Forum Moderators: coopster & phranque

Message Too Old, No Replies

From PHP to PERL!

I wanna start learning PERL ..

         

anshul

6:20 am on Nov 10, 2005 (gmt 0)

10+ Year Member



Many times, I overheard advantages to PERL over PHP. My interest in PERL is growing. In past few months, I installed PERL on Windows/Apache and tested few scripts.

However, though I understand PHP well, I can't understand PERL: like making database connections.

I've a curious question, is PERL better than PHP. My intension to use PERL is to code a spider that can quickly fetch 'backlinks' and 'urls' for a Web site.

Please show me the direction. I don't like theory much (some basics are surely, I need read). Fine examples, that I can test on local Windows/Apache, I hope makes me understand PERL.

I would like to repeat my first question: is PERL better than PHP? (context Web spider).

coopster

3:00 pm on Nov 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



No, and neither is PHP better than Perl. Each can handle server-side work equally. Each has it's own unique language and constructs (mostly based on the C programming language). Both have tight integration with the Apache HTTP server.

In this case I would use the language you are most comfortable with that will allow you to design your code with ease the whole while maintaining a strong measure of security and a path for future patches and enhancements.

As far as learning the language itself, it nevers hurts to have another tool in your belt. Perl is powerful and fun, as is PHP.

rocknbil

5:50 pm on Nov 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



However, though I understand PHP well, I can't understand PERL: like making database connections.

Perl is not that much different than php, really. You connect to DB's using the perl module DBI, which can connect to various database types.

[search.cpan.org...]

If you want to start playing with databases on your local machine, download and install a local copy of mysql.

[dev.mysql.com...]

You can then write a few example scripts and just execute them in DOS (Start->Run, type cmd for XP, command for win 98.) Let the fun begin! :-)

anshul

5:47 am on Nov 11, 2005 (gmt 0)

10+ Year Member



Thank you very much.
Yes, I'm using MySQL evreyday.

I've one specific question (I mentioned already):

Is PERL more suitable for making a spider/crawler. What about PHP Snoopy and PHP cURL in context to if better PERL can do..

With Google inspiration, I hope to make a spider for crawling and indexing Indian Web sites. May be just a study or research.

lexipixel

4:05 pm on Nov 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is PERL more suitable for
making a spider/crawler.

I don't know what PHP has to build a crawler, but you can code one in Perl pretty quick using-

use LWP::UserAgent;

SeanW

10:33 pm on Nov 12, 2005 (gmt 0)

10+ Year Member




Is PERL more suitable for making a spider/crawler

Perl has some modules that help spidering and parsing of pages. This is why I think in this case it's better than PHP. I'd look at LWP::RobotUA and HTML::TokeParser for fetching and parsing the pages respectively. One of the last chapters of "LWP&Perl" goes through the development of a spider, I think they use those modules (don't have the book handy).

Sean

Animated

2:20 am on Nov 27, 2005 (gmt 0)

10+ Year Member



great thread its whats on my mind too:)
i want to make my own scripts too for my web sites and i was thinking if you can make CGI type scripts with php too?

volatilegx

9:04 pm on Dec 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> if you can make CGI type scripts with php too?

Sure you can.

In fact, CGI is even easier with PHP than with Perl (at least it requires less code).

CGI Parameters passed into a PHP script do not have to be "unpacked" as they do in Perl, and they are automatically assigned to variables named after their respective parameter names. They are also contained in holder arrays, like $_POST and $_GET. See [php.net...]

Personally, when working with databases, I prefer using PHP's internal database interaction functions to Perl's DBI module.

DrDoc

3:56 am on Dec 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Although I find that things (day-to-day stuff) are usually simpler in PHP, there is nothing I have not been able to do in Perl (whereas I have run into restrictions with PHP).

The "automated" unpacking and variable assigning can make for sloppy programming if you are not careful (can we say "register globals"? Yuck!)

VectorJ

3:21 am on Dec 31, 2005 (gmt 0)

10+ Year Member



To make a spider in perl, a good way to start is by using the WWW::Mechanize module. In my experience making a spider, I fork several different Mech spiders and have them report to several different daemons via sockets. To coordinate the spiders, you'll need a daemon that sends new urls to the spiders, a daemon that receives urls that have been spidered already as well as the data collected from each page spidered, and a daemon to handle translation of unique words encountered into their word IDs stored in the database. This is similar to the basic schema Google used when it first started out. You'll also need scripts to retrieve the data from the database, and a good database schema. This is the sort of project that gets big and complex very quickly.

I feel that for something like spidering websites, Perl is far superior to PHP. Also, if what I'm talking about is beyond the scope of what you're trying to accomplish, you can use PHP to retrieve individual pages based on user input, but don't use curl, use the built-in PHP functions (something like file_get_contents.. I forget the actual function name).

For mass spidering though, Perl is the way to go.