qw (quote word) is used to generate a list of words. In the case above, where you use it as parameters to use module (which still wouldn't have worked, since you had a semicolon between use socket and qw). Basically, it allows you to specify a list with simple syntax. If I want to assign an array with values, I can do it like this @names = ('karthik.c', 'kevinadc', 'comatose'); which is ok I guess, but the syntax is a little ugly. I could use qw to simplify it like @names = qw(karthik.c kevinadc comatose); and that does the same thing. I guess simply said, qw is a quick way to specify a lot of little single-quoted words.
My my my. Ok, let's talk about scope. Scope is a particular area inside or between opening and closing braces. A variable in a given scope, is only accessible, inside those braces. Furthermore, the variable gets destroyed when the closing brace is reached. Let's look at an example:
#!/usr/bin/perl
my $name = "comatose";
{
my $name = "karthik.c";
}
print "$name\n";
You would probably think that the last line should print karthik.c to the screen with a newline. No. Since "my" was used inside the braces $name is a different $name than the one outside of the braces. So the one that gets assigned karthik.c, gets destroyed when it reaches the }, and now the outer $name is the only one that exists. If you remove the my from $name inside of the braces, it will work like you think:
#!/usr/bin/perl
my $name = "comatose";
{
$name = "karthik.c";
}
print "$name\n";
This prints karthik.c, not comatose as you would think. This is because we removed "my", and it is no longer local to the scope. This becomes really important when you start dealing with if's and whiles. Do you expect this to work?:
#!/usr/bin/perl
print "Enter Your Title: "; $title = <STDIN>;
print "Enter Your Name: "; $name = <STDIN>;
chomp($title);
chomp($name);
if ($title eq "Dr.") {
my $message = "Hello Doctor $name!!!!\n";
} elsif ($title eq "Mr.") {
my $message = "Mister $name, Hello!\n";
} elsif ($title eq "Mrs.") {
my $message = "Uh Oh, Married Chick!\n";
}
print "$message";
Code looks good... should work... but uh oh. my my my. $message is declared local with my inside of each elsif or if block (between each { and }). So it shows no output.