Experiments with Linux, Programming languages, Freesoftware utilities, all and all with Freesoftware.....
Tuesday, October 19, 2010
Towards the formulation of a device driver in linux
Device drivers are the programms that will be loaded on to the operating system or any other kernel program to control the functioning of various devices. The various functions include the copying of the data form a device, writing to the device, deleting a data from the device etc. Device drivers in linux include special design pattern and planning because they are directly interacting with the kernel.
Monday, October 18, 2010
String Manipulating functions in PERL
In every programming languages the string type variables are subjected to rigorous experiments by the programmers. Sorting, Splitting, Pattern matching, Concatenating, Modifying etc. PERL provides some instant functions for the manipulation of the strings. Some of them are listed below:
1: chop(string):
This will remove the last character from a string variable. It is also used in removing the escape character from the value being entered. For example:
chop("GOOD") results in a word "GOO";
2: crypt(string,salt)
The crypt function encrypts a string using the NBS Data Encryption Standard (DES) algorithm. The salt is of a two character string. It can be Numbers, Alphabets etc.
The syntax for the crypt function is as follows:
result = crypt (original, salt);
3: grep
The grep function provides a convenient way of extracting the elements of a list that match a specified pattern. (Same as that of Unix.) The syntax for the grep function is array = grep (pattern, searchlist);
For example:
@list = ("This", "is", "a", "test");
@array = grep(/^[tT]/, @list);
This will be forming a new array of list in which contains the words that have the t or T
4: splice
This function will helps to replace the values in the array at specified positions. The usage is as follows
@array = ("1", "2", "3", "4");
splice (@array, 1, 2, ("two", "three"));
The modified array will have the following contents:
("1", "two", "three", "4") : replaced the values at the index of 1 and 2
5: push
This will helps to push a new element to the end of the list . The usage of this function is as follows:
push(@array,"new");
This will add the new element "new" to the end of the @array
6:pop
This will remove the last element form the array. The usage is similar to that of the function pop.
7:split
This function is extensively used in perl for splitting the string supplied with a specific pattern in to a list of strings with the pattern. The usage of this function is as follows. Suppose the string is
$line = "This:is:a:string";
applying the split function
@list = split (/:/, $line);
The array @list contains the elements "This", "is", "a", "string"
There are many other functions for manipulating the lists based on the pattern matching. These functions provide more convinient for the programmers to use the datastructures.
1: chop(string):
This will remove the last character from a string variable. It is also used in removing the escape character from the value being entered. For example:
chop("GOOD") results in a word "GOO";
2: crypt(string,salt)
The crypt function encrypts a string using the NBS Data Encryption Standard (DES) algorithm. The salt is of a two character string. It can be Numbers, Alphabets etc.
The syntax for the crypt function is as follows:
result = crypt (original, salt);
3: grep
The grep function provides a convenient way of extracting the elements of a list that match a specified pattern. (Same as that of Unix.) The syntax for the grep function is array = grep (pattern, searchlist);
For example:
@list = ("This", "is", "a", "test");
@array = grep(/^[tT]/, @list);
This will be forming a new array of list in which contains the words that have the t or T
4: splice
This function will helps to replace the values in the array at specified positions. The usage is as follows
@array = ("1", "2", "3", "4");
splice (@array, 1, 2, ("two", "three"));
The modified array will have the following contents:
("1", "two", "three", "4") : replaced the values at the index of 1 and 2
5: push
This will helps to push a new element to the end of the list . The usage of this function is as follows:
push(@array,"new");
This will add the new element "new" to the end of the @array
6:pop
This will remove the last element form the array. The usage is similar to that of the function pop.
7:split
This function is extensively used in perl for splitting the string supplied with a specific pattern in to a list of strings with the pattern. The usage of this function is as follows. Suppose the string is
$line = "This:is:a:string";
applying the split function
@list = split (/:/, $line);
The array @list contains the elements "This", "is", "a", "string"
There are many other functions for manipulating the lists based on the pattern matching. These functions provide more convinient for the programmers to use the datastructures.
Sunday, October 17, 2010
PERL: A hub of magnificient inbuilt functions, Data structures
PERL have amble amount of inbuilt functions and data structures. While we started implementing this structures in C language it will have to take more pain...(HEY not diminishing the C language..PERL itself is written in C). These structures will be helpful for programmers to implement their complex softwares with little effort..
ASSOCIATIVE ARRAYS.....
Associative arrays are a typical data structure which works like a hashing table. Each entry in the associative array have two attributes,: 1)value 2)keys
This typical array can store two values in its first index. This is similar in the case of a student record with student name and roll number. We can retrieve the values as well as the names from the associative array according to our convenience..
Associative array can be declared as "%asso" .The easiest way to create an associative array item is just to assign to it. For example, the statement:
$aasso{"bananas"} = 1;
will assign associative array " asso" with its first element as "bananas" and the value is 1 . Similarly we can add any number of elements to this associative array. One if the flexibility of this associative array is described below. Suppose we have an array say
"@names=("john",24,"abel",45,"jeas",67)".
We can convert this to an associative array by a simple statement
"%names=@names"
For getting the values from the associative arrays we have two main functions as described above:
They are mainly used for getting the values and attributes in the associative array: Their usage is as follows:
"@nameslist = keys(%names);"
This will returns a list called "namelist". The datas in the name list will not be in sorted order. We can sort this by using the function "sort keys(%names)."
"@valueslist = values(%names);"
This will return the list of the values of the elements in the associative array.
The associative array is the pioneer for other data structures like linked list,tree etc in perl. Also the massive Hash tables can be implemented with less effort by using the associative array....
ASSOCIATIVE ARRAYS.....
Associative arrays are a typical data structure which works like a hashing table. Each entry in the associative array have two attributes,: 1)value 2)keys
This typical array can store two values in its first index. This is similar in the case of a student record with student name and roll number. We can retrieve the values as well as the names from the associative array according to our convenience..
Associative array can be declared as "%asso" .The easiest way to create an associative array item is just to assign to it. For example, the statement:
$aasso{"bananas"} = 1;
will assign associative array " asso" with its first element as "bananas" and the value is 1 . Similarly we can add any number of elements to this associative array. One if the flexibility of this associative array is described below. Suppose we have an array say
"@names=("john",24,"abel",45,"jeas",67)".
We can convert this to an associative array by a simple statement
"%names=@names"
For getting the values from the associative arrays we have two main functions as described above:
They are mainly used for getting the values and attributes in the associative array: Their usage is as follows:
"@nameslist = keys(%names);"
This will returns a list called "namelist". The datas in the name list will not be in sorted order. We can sort this by using the function "sort keys(%names)."
"@valueslist = values(%names);"
This will return the list of the values of the elements in the associative array.
The associative array is the pioneer for other data structures like linked list,tree etc in perl. Also the massive Hash tables can be implemented with less effort by using the associative array....
Saturday, October 16, 2010
The cdrom checker perl code.......
Perl program strikes again....
Considering a situation in which you wanted to know about the contents of the CDROM or DVD. You wanted to list all the files in the removable media. For this necessity you can hold the perl program iin tight..
The following perl code will scans the device file and if any cdrom or dvd is in the drive it will print the files in it. All we wanted to run the perl code in a terminal..
--------------------------------------------------------------------------
system("ls /media > mediaoutput");
if(open(MY,"mediaoutput"))
{
$line=<MY>;
while($line ne "")
{
if($line == "cdrom")
{
system ( "ls /media/cdrom > lsout");
}
$line=<MY>;
}
}
if (open(LS,"lsout"))
{
$lin = <LS>;
while($lin ne "")
{
print $lin;
$lin=<LS>;
}
}
------------------------------------------------------------------------
It can make use of UNIX system call to work as if we are on terminal. The above code will first of all call the ls command over the medial file and stores the ls output to a file. The it will scan for the file called cdrom. If found it will again run ls command over the cdrom to print out the list of files to another output file. The last IF loop is for printing the contents of the file output due to the command execution of system call over the cdrom. If there is no any devices are connected to the computer nothing will be happened. The notion $line=<MY> is the method of giving the input file line by line
Considering a situation in which you wanted to know about the contents of the CDROM or DVD. You wanted to list all the files in the removable media. For this necessity you can hold the perl program iin tight..
The following perl code will scans the device file and if any cdrom or dvd is in the drive it will print the files in it. All we wanted to run the perl code in a terminal..
--------------------------------------------------------------------------
system("ls /media > mediaoutput");
if(open(MY,"mediaoutput"))
{
$line=<MY>;
while($line ne "")
{
if($line == "cdrom")
{
system ( "ls /media/cdrom > lsout");
}
$line=<MY>;
}
}
if (open(LS,"lsout"))
{
$lin = <LS>;
while($lin ne "")
{
print $lin;
$lin=<LS>;
}
}
------------------------------------------------------------------------
It can make use of UNIX system call to work as if we are on terminal. The above code will first of all call the ls command over the medial file and stores the ls output to a file. The it will scan for the file called cdrom. If found it will again run ls command over the cdrom to print out the list of files to another output file. The last IF loop is for printing the contents of the file output due to the command execution of system call over the cdrom. If there is no any devices are connected to the computer nothing will be happened. The notion $line=<MY> is the method of giving the input file line by line
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...
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...
Thursday, October 14, 2010
STARTS A BLOG
The day 14th October is a memorable day for me that i started my blog seriously. Prior to this blog i have experienced with starting two other blogs. But unfortunately it remained with the URL for many days...
It's time for me to introduce myself....
I am Johnpaul C I, graduated in Computer Science and Engineering from Government Engineering College Sreekrishnapuram, Palakkad.....
The college of Engineering Sreekrishnapuram stood still in its rules for promoting the popularity of free software utilities. So I was brought up in an environment of free soft wares. I started uphill the Linux right from my first semester classes onwards and started using the Linux actively when I joined the classes at Thrissur under a Linux Enthusiast and programmer at IC soft wares....
This blog will share the various snippets of programming languages, Amazing nature of different programming languages, Intresting programm codes, Different free software utilities, Facts ..and more......
It's time for me to introduce myself....
I am Johnpaul C I, graduated in Computer Science and Engineering from Government Engineering College Sreekrishnapuram, Palakkad.....
The college of Engineering Sreekrishnapuram stood still in its rules for promoting the popularity of free software utilities. So I was brought up in an environment of free soft wares. I started uphill the Linux right from my first semester classes onwards and started using the Linux actively when I joined the classes at Thrissur under a Linux Enthusiast and programmer at IC soft wares....
This blog will share the various snippets of programming languages, Amazing nature of different programming languages, Intresting programm codes, Different free software utilities, Facts ..and more......
Subscribe to:
Posts (Atom)