On Sat, 31 Jan 2009, Hasib wrote:
> Now i want to learn a Scripting language I am in dilemma what
> to choose, Perl, Ruby, Python ?.suggest me any of above which
> will suite to my domain.
>
> Comments / Feedback's are welcome.
>
A scripting language is best 'used' as a 'Shopping cart' !
(yes the one you encounter at the super market).
This metaphor helps us see:
. a shopping cart is used for a specific purpose
. a different shopping cart may be useful for another purpose
. a shopping cart is use and leave
. a shopping cart has a specified capacity
. a shopping cart sometimes hits the aisles
. a shopping cart is a means to an end
. we carry the purchased items to our home and not the shopping cart
. a shopping cart is not a car
Here is a partial list of shopping carts:
. PERL
. Python
. Ruby
. PHP
. Lua
. Rebol
. TCL
...
You say, your focus area is 'Data Networks' - sockets,
protocols and stuff like that.
As an illustrative example.
Here is a RUBY version.
require 'socket'
include Socket::Constants
backlog = 5
socket = Socket.new( AF_INET, SOCK_STREAM, 0)
sockaddr = Socket.pack_sockaddr_in( 9999, '10.10.10.10')
socket.bind( sockaddr )
socket.listen( backlog )
...
Here is a PERL version.
use Socket;
$backlog = 5;
socket( SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
setsockopt( SERVER, SOL_SOCKET, SO_REUSEADDR, 1);
$sockaddr = sockaddr_in( 9999, '10.10.10.10');
bind( SERVER, $sockaddr );
listen( SERVER, $backlog );
...
The difference between the Ruby and PERL version are cosmetic.
(variable prefix '$' and statement terminator ';').
The only way you can write a program of this kind in any
scripting language is if you "understand sockets" and
"tcp state machine".
(actually copy-and-paste is another possibility)
Just to make life more realistic, try to add support for
. Multi-threading
. Signal handling
Thats how most servers are implemented. i'm sure both of these
must be trivial matters for those who do scripting.
My suggestion:
Prefer "use and throw" rather than "being stuck" when it comes
to scripting languages.
The rest is upto you !
thanks
Saifi.