Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Programming Scripts Articles
Page 29 of 33
Sending an HTML Message using Perl
If you want to send HTML formatted email using sendmail, then you simply need to add Content-type: text/html in the header part of the email as follows −#!/usr/bin/perl $to = 'abcd@gmail.com'; $from = 'webmaster@yourdomain.com'; $subject = 'Test Email'; $message = 'This is test email sent by Perl Script'; open(MAIL, "|/usr/sbin/sendmail -t"); # Email Header print MAIL "To: $to"; print MAIL "From: $from"; print MAIL "Subject: $subject"; print MAIL "Content-type: text/html"; # Email Body print MAIL $message; close(MAIL); print "Email Sent Successfully";
Read MoreSending a Plain Message using Perl
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 different for your Linux/Unix machine.#!/usr/bin/perl $to = 'abcd@gmail.com'; $from = 'webmaster@yourdomain.com'; $subject = 'Test Email'; $message = 'This is test email sent by Perl Script'; open(MAIL, "|/usr/sbin/sendmail -t"); # Email Header print MAIL "To: $to"; print MAIL "From: $from"; print MAIL "Subject: $subject"; # Email Body print MAIL $message; close(MAIL); ...
Read MoreMatching Boundaries & Selecting Alternatives in Perl
Matching Boundaries in PerlThe \b matches at any word boundary in Perl, as defined by the difference between the \w class and the \W class. Because \w includes the characters for a word, and \W the opposite, this normally means the termination of a word. The \B assertion matches any position that is not a word boundary. For example −/\bcat\b/ # Matches 'the cat sat' but not 'cat on the mat' /\Bcat\B/ # Matches 'verification' but not 'the cat on the mat' /\bcat\B/ # Matches 'catatonic' but not 'polecat' /\Bcat\b/ # Matches 'polecat' but not 'catatonic'Selecting Alternatives in PerlThe | character is just like ...
Read MoreFilehandle Special Variables in Perl
There are various File Handle related Special Variables in Perl. We have listed them in different below in tabular form:$|If set to nonzero, forces an fflush(3) after every write or print on the currently selected output channel.$OUTPUT_AUTOFLUSH$%The current page number of the currently selected output channel.$FORMAT_PAGE_NUMBER$=The current page length (printable lines) of the currently selected output channel. Default is 60.$FORMAT_LINES_PER_PAGE$-The number of lines left on the page of the currently selected output channe$FORMAT_LINES_LEFT$~The name of the current report format for the currently selected output channel. Default is the name of the filehandle.$FORMAT_NAME$^The name of the current top-of-page format for the ...
Read MoreRegular Expression Special Variables in Perl
There are various Regular Expression Special Variables in Perl. We have listed them in different below in tabular form −$digitContains the text matched by the corresponding set of parentheses in the last pattern matched. For example, $1 matches whatever was contained in the first set of parentheses in the previous regular expression.$&The string matched by the last successful pattern match.$MATCH$`The string preceding whatever was matched by the last successful pattern match.$PREMATCH$'The string following whatever was matched by the last successful pattern match.$POSTMATCH$+The last bracket matched by the last search pattern. This is useful if you don't know which of a ...
Read MoreGlobal Special Variable Types in Perl
There are various global special variables in Perl. We have listed them in different blocks based on their usage and nature −Global Array Special Variables@ARGVThe array containing the command-line arguments intended for the script.@INCThe array containing the list of places to look for Perl scripts to be evaluated by the do, require, or use constructs.@FThe array into which the input lines are split when the -a command-line switch is given.Global Hash Special Variables%INCThe hash containing entries for the filename of each file that has been included via do or require.%ENVThe hash containing your current environment.%SIGThe hash used to set signal ...
Read MoreThe confess Function in Perl
The confess function in Perl is like cluck; it calls die and then prints a stack trace all the way up to the origination script.package T; require Exporter; @ISA = qw/Exporter/; @EXPORT = qw/function/; use Carp; sub function { confess "Error in module!"; } 1;When called from a script like below −use T; function();It will produce the following result −Error in module! at T.pm line 9 T::function() called at test.pl line 4
Read MoreThe croak Function in Perl
The croak function in Perl is equivalent to die, except that it reports the caller one level up. Like die, this function also exits the script after reporting the error to STDERR −package T; require Exporter; @ISA = qw/Exporter/; @EXPORT = qw/function/; use Carp; sub function { croak "Error in module!"; } 1;When called from a script like below −use T; function();It will produce the following result −Error in module! at test.pl line 4As with carp, the same basic rules apply regarding the including of line and file information according to the warn and die functions.
Read MoreThe cluck Function in Perl
The cluck function in Perl is a sort of supercharged carp, it follows the same basic principle but also prints a stack trace of all the modules that led to the function being called, including the information on the original script.package T; require Exporter; @ISA = qw/Exporter/; @EXPORT = qw/function/; use Carp qw(cluck); sub function { cluck "Error in module!"; } 1;When called from a script like below −use T; function();It will produce the following result −Error in module! at T.pm line 9 T::function() called at test.pl line 4
Read MoreThe carp Function in Perl
The carp function in Perl is the basic equivalent of warn and prints the message to STDERR without actually exiting the script and printing the script name.package T; require Exporter; @ISA = qw/Exporter/; @EXPORT = qw/function/; use Carp; sub function { carp "Error in module!"; } 1;When called from a script like below −use T; function();It will produce the following result −Error in module! at test.pl line 4
Read More