Saturday, October 16, 2010

The glittering facts about perl language...

The perl programming language is also called as scripting language. The excellent properties of perl language includes various inbuilt data structures, pattern matching techniques, simple file operations, system call facilities,
more over it is widely used to write programs in an erotic manner. The definition of the PERL is Practical Extraction and  Report Language. A small compiler can be made with the help of the perl language utilising the pattern matching capability. Several other day today needs(programming) can be fulfilled by small perl codes

The following perl codes will bring some humor in the sense of our needs. Once I wanted to get the email addresses of all my friends from a text document for starting a group id. It will be a tedious job for scanning all the textual matter and obtain the email id. I thought of a perl program that consumes a text file(files) as input and produces an output file that contains all the email id of my friends..

-----------------------------------------------------------------------
while($line=<>)
{
   while($line=~ /( [a - zA-Z0-9\_\.]+\@)([a-zA-Z\.]+)/g)
     {
        open(out, ">output");
        select("out");
        print STDOUT ("$&\n");
      }
}
--------------------------------------------------------------------------------- 
We can give any number of input files to this to this program. The first loop will consumes the input files one by one. The second loop will scan each files individually. It will take each line from the input file, check for the pattern for email address, If found it will open an output file output, select it and print the matched email address to it.

The pattern ( [a - zA-Z0-9\_\.]+\@)([a-zA-Z\.]+)  is the main "worker" in the code. It suggests that all the characters followed by the alphabets or numbers with @ sign, follows all the characters with a full stop. The matched stirng will be stored in a system variable "$&". Which meant form the email id abd67@gmail.com.. We can make use of the same programming pattern for extracting required strings by changing the pattern...

No comments:

Post a Comment