Jump to content

Perl or PHP for building a bot.


lilman

Recommended Posts

I want to learn how to develop bots.  I am familiar with PHP, but I have heard to build a bot, you should use Perl.  I was wondering if anyone could enlighten me a little more.  Which do you think is better, does PHP limit the type of things your bot can do?

Link to comment
Share on other sites

there isn't really anything Perl can do that PHP can't.

 

I'm just going to hang around a while and wait for effigy to pop in. :)

 

And on the perl vs. PHP argument - I'd say use perl. PHP is relatively inefficient, and the vast majority (all, possibly) of unix-like operating systems will have perl, but it's very likely that they won't have PHP. Perl is nearly a unix necessity.

Link to comment
Share on other sites

I would agree that perl is much better suited for bots. Ruby is also a nice language for writing bots. If you are writing an irc bot you can look at this one that I wrote a long time ago http://www.phpfreaks.com/forums/index.php/topic,123057.msg508186.html#msg508186. It is a really basic bot but it should give you a decent starting point. One thing that I have noticed is that the php bot is a lot harder on the server then my Ruby bot.

Link to comment
Share on other sites

I don't know if PHP's PEAR has excellent tools like WWW::Mechanize to help you lay a powerful foundation.
Curl :)

And you don't need PEAR for it.

 

I meant excellent. I haven't used CURL, but after skimming the docs the UI looks terrible and it still seems to fall short of what Mechanize is capable of; perhaps I'm missing something.

Link to comment
Share on other sites

Okay, you win, PHP sucks.

 

After you use it long enough, and after you experience perl, python, and other scripting languages, you'll slowly come to the realization that PHP is, indeed, inferior from a technical standpoint. (I suppose that, too, is subjective, but I haven't heard a single knowledgable person say that PHP is better than perl or python.)

Link to comment
Share on other sites

Well PHP can do pretty much everything that is needed for running most websites, and it's fast to code in since it already has most of the functions you'll need built in. Wouldn't it take longer to make the same site in say python or perl?

Link to comment
Share on other sites

Wouldn't it take longer to make the same site in say python or perl?

 

You're right, there are some parts of PHP that have advantages over perl, and the same functionality in PHP and perl would probably be much easier to write in PHP. (And I've never actually heard of python being used for web sites, but it's definitely possible.) For example, PHP has database connection support built into it, but with perl, you need to use an external module.

 

And I suppose I ought to say what I should have said a long time ago - I'm referring to their proficiency from a scripting point of view, not necessarily web sites. When I write any script, I use these languages, in this order: bash, python, perl. I never use PHP, and I use bash and python before perl for the simple reason that I'm more familiar with them. PHP is very clunky and inefficient for regular scripts. I imagine this could have saved a lot of discussion if I'd said it in the first place, but I suppose someone may have learned from it, so it's not all bad. :)

Link to comment
Share on other sites

Python is... interesting. In most languages, whitespace is trivial, nothing to be worried about. Sure, proper indentation is nice, but it's not required. NOT the case in python. :) Indentation is a crucial part of python syntax, and how it knows where a particular loop, method, class, etc., starts and ends. For example:

 

#!/usr/bin/python

class Person:
    def __init__(self):
        self.firstname = ""
        self.lastname = ""

    def set_firstname(self, value):
        self.firstname = value

    def set_lastname(self, value):
        self.lastname = value

def main():
    person = Person()
    person.set_firstname("John")
    person.set_lastname("Doe")

 

That's very rudimentary, but you get the idea. Once you un-indent, you leave the current construct. Another quirk is that methods in a class always take a reference to the owning object as the first argument, but the reference is not passed in the actual method call. :)

 

One thing that I really like about python (but takes some getting used to) is the ease with which you can read code. It's written very naturally, with relatively few non-alphanumeric symbols. For example, to write a basic condition:

 


some_bool = True

if some_bool:
    print "The variable some_bool is not false."

if not some_bool:
    print "The variable some_bool is false."

 

Note the complete absence of parentheses around the condition, and you simply write "if not" instead of "if !some_bool".

 

Regarding efficiency: I haven't run any tests, but for all practical purposes, python and perl are very comparable when you use them for scripting. When you bind python to GTK or Qt, however, it starts to slow down - but that's to be expected, with an interpreted language. One little thing that I imagine helps in the efficiency arena is that when you first run a python script, it compiles it to a binary, and as long as you don't change the script, it transparently uses the byte-compiled binary every time after that. (Every time you run the script, it compares the file's mtime to a value stored in the binary, and updates it if it's required.)

 

Regarding functionality: Just as there are hundreds of modules written for extended functionality in perl, there are hundreds of packages that provide bindings for python. PyGTK allows you to create GTK apps with python, dbus-python allows you to send and monitor dbus signals, and so on and so forth. I'm sure there are more written for perl, but I have yet to encounter a situation in python that I haven't been able to find a pre-written solution.

 

And regarding objects in python: I think its OO support is excellent, although, as with perl, I haven't really tried anything too tricky.

Link to comment
Share on other sites

For example, the traditional "Hello, world!" program, written in bash. (With a few added features, just for fun)

 

#!/bin/bash

if [[ -n $1 ]] ; then
    times=$1
else
    times=3
fi

i=0

while [ "$i" -lt "$times" ] ; do
    echo "Hello, world!\n"
    i=$((${i} + 1))
done

return 0

 

In bash, 0 is the value returned when a script has executed successfully.

 

Edit: Holy infinite loop, Batman!

Link to comment
Share on other sites

And I've never actually heard of python being used for web sites, but it's definitely possible.

 

I'm quite sure that I've seen a page on Google ending with .py somewhere...

Google uses both PHP and Python

you will see it analytics

answers.py

Link to comment
Share on other sites

Which is faster for websites? PHP or Python?

Both of them are Interpreted language. I've never used Python . What I can say is PHP is Much Much more faster than perl and thats the main cause for which so many developers switched to PHP from perl. in case of CLI programms there is not any big difference of speed in any language. although I've hard that python is also fast like PHP . VNC itself is actually made by perl and its GUI by Java (in Linux).

But why dont you use C++ ??

C++ TCP sockets are easy and reliable.

Link to comment
Share on other sites

Which is faster for websites? PHP or Python?
But why dont you use C++ ??

C++ TCP sockets are easy and reliable.

I think that it would take a long time to learn all of the C++ that I will need for my web applications, and that it would take a lot longer to write the code for them in C++..
Link to comment
Share on other sites

in case of CLI programms there is not any big difference of speed in any language.

 

Actually, PHP is very slow when compared to other cli tools, Bash, Perl, Python and Ruby.

 

And just to let you all know, there are probably more web sites written in Python than you realise. it actually has very good support (modules / frameworks) for web developement. Just take a look at mod_python, Internet proticols & support, zope and django.

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.