Hi Anant! Here's some review of your code:
On Thursday 22 Oct 2009 12:23:55 Anant Gupta wrote: > I wrote > > #!usr/bin/perl > use Socket; 1. You should add "use strict;" and "use warnings;" at the top of every file. Writing programs without them is dangerous. Probably the only instance where they may be omitted is in very simple perl -e scripts (see perldoc perlrun) and possibly some other short scripts where they get in the way. Which book or tutorial have you been using to learn Perl? It's probably not very good. Please look at http://perl-begin.org/ for some recommendations. (Many of which are available online). 2. You should probably use IO::Socket and its friends or something. It hides the DNS nitty-gritty details for you. If you want to speak a protocol above TCP or UDP, then there are plenty of fine client and server modules on CPAN. Just go to http://search.cpan.org/ or http://kobesearch.cpan.org/ and search for the protocol (or ask us). No need to re-invent an ad-hoc and incomplete wheel, which will later have to be maintained and enhanced, and become a permanent part what we call the "darkpan", which is all the Perl code that's not on the CPAN, or even in different open-source projects. > use constant ADDR => 'www.google.com'; > my $name=shift || ADDR; You probably want: <<< my $name = shift || ADDR; >>> And please separate paragraphs with blank lines. All use constants should be in their own paragraph or a few. Perl Best Practices (PBP) has some issues with "use constant" which I tend to agree with. It recommends using Readonly variables (see http://search.cpan.org/dist/Readonly/ ) but I prefer just doing something like: <<< my $default_addr = 'www.google.com'; >>> Or: <<< our $default_addr = 'www.google.com'; >>> and make them mutable but constant by discipline and convention variables. > $packed=gethostbyname($name); Use my and again - surround a "=" by spaces. > $dotted-inet_ntoa($packed); This is a void expression. You probably want "=" instead of "-". > print "DOtted Address is $packed"; You have a typo here - "DOtted" instead of "Dotted". And you probably want a trailing \n to print a newline. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ The Case for File Swapping - http://shlom.in/file-swap Chuck Norris read the entire English Wikipedia in 24 hours. Twice. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/