5% assure discount from here only

Some useful Perl Operations

This page is going to be full of Perl Operations day by day. Every topic related to PERL is going to be included overhere. Some of the topics going to be here are Strings, Subroutines, CGI Programming, Modules, Web Programming, XML Technologies, Pattern Matching, Regular Expressions, Database Programming, OOPS.

(1) quotes in PERL

Following types of quotes are there with their different meanings;

(a) Single quotes ('')

Single quotation marks are used to enclose data you want taken literally.

#!/usr/bin/perl -w
use strict;

my $value;
$value = 7;
my $check = 'it is worth $value';
print $check;

#prints it is worth $foo


(b) Double quotes ("")

Double quotation marks are used to enclose data that needs to be interpolated before processing.


#!/usr/bin/perl -w
use strict;

my $value;
$value = 7;
my $check = "it is worth $value";
print $check;

#prints it is worth 7

(c) Escape Characters (\\)


#!/usr/bin/perl -w
use strict;

my $value;
$value = 7;
my $check = "it is \"worth"\ $value";
print $check;

#prints it is "worth" 7

(d) Quoting without quotes

There are three simple methods of doing this with the letter q.
In the following three sections, on the subjects of q, qq, and qw notation.

(i) q

The first way to quote without quotes is to use q() notation.

#!/usr/bin/perl -w
use strict;
my $foo;
my $bar;
$foo = 7;
$bar = q(it is 'worth' $foo);
print $bar;

# print it is 'worth' $foo

(ii) qq

In the same way that double-quotes add interpolation to the functionality of single-quotes, doubling the q adds interpolation to quoting without quotation marks.

#!/usr/bin/perl -w
use strict;
my $foo;
my $bar;
$foo = 7;
$bar = qq(it is "worth" $foo);
print $bar;

# print it is "worth" 7

(iii) qw

You can use qw to quote individual words without interpolation.

@baz = ('one', 'two', 'three');

@baz = qw(one two three);

(iv) here documents

If you want to quote many lines of text literally, you can use "Here Document" notation. This consists of an introductory line which has two open angles (aka "angle brackets": << ) followed by a keyword — the end tag — for signalling the end of the quote.


#!/usr/bin/perl -w
use strict;
my $foo = 123.45;
my $bar = "Martha Stewedprune";
print <<"EOT"; 
=====

This is an example of text taken literally except that variables are expanded where their variable names appear.
foo: $foo
bar: $bar
EOT 
#print =====

This is an example of text taken literally except that variables are expanded where their variable names appear.
foo: 123.45
bar: Martha Stewedprune