[WpProQuiz 2]
[WpProQuiz_toplist 2]
Perl Quiz on Data Types
Learning through sharing
[WpProQuiz 2]
[WpProQuiz_toplist 2]
Our team always face email existence problem when they try to:
Well it’s not possible to know 100% whether given e-mail address exists in real or not but it will be handy in majority of the cases. You can do it manually also if you are in Linux box using host or nslookup and telnet command. I would prefer host command for this purpose.
How it works:
Here many things came into the picture while testing various mail ids from various mail handlers. I will discuss it under “possible ways of failures”
Steps to check the email existence manually
1. Get the mail id to verify (we can get domain-name from this format to use it in our next step userid@domain-name . For ex:admin@aliencoders.org)
2. Either use nslookup command or host command to get mail server address (Lists of mx records from DNS)
a. Using nslookup:
nslookup –type=mx domain-name
b. Using host :
host –t mx domain-name
3. Get the least digital value’s mx record to use it in telnet
a. telnet mxrecord port-no i.e. telnet mail.aliencoders.org 25
b. Once connected use SMTP commands to know if email id exists or not. It will return 250 as a return code with OK or Accepted. Depending upon mail server configuration and Linux flavors too.
Let’s see it practically with all combination of commands, inputs and outputs š
Output from nslookup (it will show many more things which I have not shown here)
$ nslookup -type=mx gmail.com
Non-authoritative answer:
gmail.com mail exchanger = 20 alt2.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 5 gmail-smtp-in-v4v6.l.google.com.
gmail.com mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.
Output from host command ( I prefer this over nslookup )
$ host -t mx gmail.com
gmail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 5 gmail-smtp-in-v4v6.l.google.com.
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.
Get the value which has lowest ranked digit. In this case it is 5 so take gmail-smtp-in-v4v6.l.google.com for our purpose
Either use host or nslookup for the first stage.
Telnet outputs:
Step 1
telnet gmail-smtp-in-v4v6.l.google.com 25
Trying 173.194.77.27…
Connected to gmail-smtp-in-v4v6.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP hk4si16050652obc.168
Step 2 (type helo, if it didn’t work try helo hi, if it didn’t work too try ehlo then )
helo
250 mx.google.com at your service
Step 3 (type any valid email id. Invalid email id will say ok but after rcpt to it will throw an error and don’t skip this step)
mail from: <sanjeev@aliencoders.org>
250 2.1.0 OK hk4si16050652obc.168
Step 4 (You need to provide email which needs to be verified. Ok means it may exists. Not 1005 guaranteed on existence but we can infer that this email id may work)
rcpt to: <jassics@gmail.com>
250 2.1.5 OK hk4si16050652obc.168
Telnet outputs on failure (Various reasons are there)
1. Network is unreachable. (sometimes it is reachable form one host but not from others)
telnet gmail-smtp-in-v4v6.l.google.com 25
Trying 74.125.127.26…
telnet: connect to address 74.125.127.26: Connection timed out
Trying 2001:4860:8005::1b…
telnet: connect to address 2001:4860:8005::1b: Network is unreachable
telnet: Unable to connect to remote host: Network is unreachable
2. Error at mail from:<mail-id> :
3. If email id exists but it doesn’t show up 250/ok then below reasons may justify this:
Steps to check email existence using Perl
Good thing with this script is:
Here is the fully working Perl script
Why still this trick doesn’t assure 100% proof that email id exists or not?
There can be many reasons for not trusting on this script or the above said manual steps. Best way is to send an email to the given email id. If it bounced back, means it doesn’t exist or can’t be delivered. (I chat with a person in gtalk but can’t send an email to that person. Strange isn’t it).
Note: This was just for educational purpose and found helpful for web masters or admins. Don’t use it as spam stuffs, you IP address and your mail id will be blacklisted. Like admin@aliencoders.org has been blacklisted from various mail servers.
“delete” function in Perl is mainly used to delete the given element/key, which in return deletes its associated value(s) too. So, exists() on such key would return false.
Note: Assigning undefined value to a key in has doesn’t remove its key but delete() function would do that. So, use delete() or assigning undefined value wisely.
The general syntax for delete function is:
[perl]delete EXPR
[/perl]
Welcome to Perlistan world! I have been using Perl (Perl 5.10 specifically) from last 1 year and I am really fond of this programming language. There are hell lots of features exist for Perl but I have written only few which I felt is important and interesting for beginners.
Introduction
Perl (Practical Extraction & Report Language) is the Swiss Army knife for scripting languages(rather call it programming language): powerful and adaptable. It was first developed by Larry Wall, a linguist working as a systems administrator for NASA in the late 1980s, as a way to make report processing easier.
Since then, it has moved into a large number of roles: automating system administration, acting as glue between different computer systems; and, of course, being one of the most popular languages for CGI programming on the Web.
Why did Perl become so popular when the Web came along?
There may be at least two most important reasons:
First, most of what is being done on the Web happens with text, and is best done with a language that's designed for text processing. More importantly, Perl was appreciably better than the alternatives at the time when people needed something to use. C is complex and can produce security problems (especially with untrusted data), Tcl can be awkward and Python didn't really have a foothold.
Second: It also didn't hurt that Perl is a friendly language. It plays well with your personal programming style. The Perl slogan is “There's more than one way to do it,'' The growth of Internet also complemented Perl. The initial attempt at providing dynamic content was through CGI (even now CGI is used extensively), and Perl's remarkable text handling features made it a quick fit. CGI programming is now synonymous with Perl programming.
CPAN – Comprehensive Perl Archive Network, was set up to share Perl code. Perl supports modules and chances are that for 99% of the programming requirements, there is already a tested module in CPAN (for the remaining 1%, write modules and contribute to CPAN!). Using modules really mask the complexities of adhering to pre-defined standards and frees you to concentrate on your tasks – no point in re-inventing the wheel. Now, you have modules which handles graphics, CGI etc… You can also embed Perl code in your C/C++ programs. A very popular embedded Perl architecture is mod_perl for Apache web server.
Data manipulation
Perl can handle strings, dates, binary data, database connectivity, streams, sockets and many more. This ability to manipulate multiple data types help immensely in data conversion (and by the way, it is much faster than PL/SQL!). Perl also has provision for lists (or arrays) and for hashes (associative arrays). Perl also supports references, which are similar to the pointers in C. Lists, hashes and references together make it possible to define and manipulate powerful custom-defined data-types.
Portability Most of the Perl code will run without any change in Unix or Windows or Macintosh. Typical changes you might have to make include specifying file paths and use of low-level OS specific functions.
CGI CGI.pm. Period. Almost all CGI programs written today are using the CGI.pm module from CPAN. Even before this was written, people used to use Perl extensively for CGI programming. CGI.pm made the process streamlined and easy, even for beginners. The graphics library GD is used extensively in producing dynamic web charts. Ever since Kernighan and Ritchie came out with C programming language, people have started learning almost any programming language with the obligatory "Hello World" program. Let us do the same!
Here is the basic perl program that we'll use to get started.
[perl] #! /usr/bin/perl
# prints Hello world.
use strict;
use warnings;
print 'Hello world.'; # Print a message [/perl]
#! is called sh-bang (she bang š ). Always let it be your first line of code in your program. Write the location of executable perl here. Always try to write use strict and use warnings in your program. It will minimize error and you will be following standard coding rules !
Comments Perl treats any thing from a hash # to the end of line as a comment. Block comments are not possible. So, if you want to have a block of comments, you must ensure that each line starts with #.
Statements Everything other than comments are Perl statements, which must end with a semicolon, like the last line above. Unlike C, you need not put a wrapping character \ for long statements. A Perl statement always ends with a semicolon.
Running Perl Write a small program using a text editor, and save it. The first line of the program is a typical shell construct, which will make the shell start the interpreter and feed the remaining lines of the file as an input to the interpreter. After you've entered and saved the program make sure the file is executable by using the command
[perl]
chmod u+x perlfile
[/perl]
at the UNIX prompt, where perlfile is the filename of the program (of course with .pl or .pm extension mostly). Now, to run the program, just type any of the following at the prompt.
[perl]
perl perlfile
[/perl]
If something goes wrong then you may get error messages, or you may get nothing. You can always run the program with warnings using the command
[perl]
perl -w progname
[/perl]
at the prompt. This will display warnings and other (hopefully) helpful messages before it tries to execute the program. To run the program with a debugger use the command
[perl]
perl -d progname
[/perl]
When the file is executed Perl first compiles it and then executes that compiled version. Unlike many other interpreted languages, Perl scripts are compiled first, helping you to catch most of errors before program actually starts executing. In this context, the -w switch is very helpful. It will warn you about unused variables, suspicious statements etc.
Subscribe now to keep reading and get access to the full archive.