Category: 09. Perl
-
Sending Email
Using sendmail Utility Sending a Plain Message If you are working on Linux/Unix machine then you can simply use sendmail utility inside your Perl program to send email. Here is a sample script that can send an email to a given email ID. Just make sure the given path for sendmail utility is correct. This may be…
-
Regular Expressions
A regular expression is a string of characters that defines the pattern or patterns you are viewing. The syntax of regular expressions in Perl is very similar to what you will find within other regular expression.supporting programs, such as sed, grep, and awk. The basic method for applying a regular expression is to use the pattern binding operators…
-
Coding Standard
Each programmer will, of course, have his or her own preferences in regards to formatting, but there are some general guidelines that will make your programs easier to read, understand, and maintain. The most important thing is to run your programs under the -w flag at all times. You may turn it off explicitly for…
-
Special Variables
There are some variables which have a predefined and special meaning in Perl. They are the variables that use punctuation characters after the usual variable indicator ($, @, or %), such as $_ ( explained below ). Most of the special variables have an english like long name, e.g., Operating System Error variable $! can…
-
Error Handling
The execution and the errors always go together. If you are opening a file which does not exist. then if you did not handle this situation properly then your program is considered to be of bad quality. The program stops if an error occurs. So a proper error handling is used to handle various type…
-
Directories
Following are the standard functions used to play with directories. Display all the Files There are various ways to list down all the files available in a particular directory. First let’s use the simple way to get and list down all the files using the glob operator − Here is another example, which opens a directory and…
-
File I/O
The basics of handling files are simple: you associate a filehandle with an external entity (usually a file) and then use a variety of operators and functions within Perl to read and update the data stored within the data stream associated with the filehandle. A filehandle is a named internal Perl structure that associates a physical file…
-
Formats
Perl uses a writing template called a ‘format’ to output reports. To use the format feature of Perl, you have to define a format first and then you can use that format to write formatted data. Define a Format Following is the syntax to define a Perl format − Here FormatName represents the name of the format.…
-
References
A Perl reference is a scalar data type that holds the location of another value which could be scalar, arrays, or hashes. Because of its scalar nature, a reference can be used anywhere, a scalar can be used. You can construct lists containing references to other lists, which can contain references to hashes, and so…
-
Subroutines
A Perl subroutine or function is a group of statements that together performs a task. You can divide up your code into separate subroutines. How you divide up your code among different subroutines is up to you, but logically the division usually is so each function performs a specific task. Perl uses the terms subroutine,…