Menu

PERL TUTORIALS - Perl Data Types

Perl Data Types

ADVERTISEMENTS

S.N.Types and Description
1Scalar:
Scalars are simple variables. They are preceded by a dollar sign ($). A scalar is either a number, a string, or a reference. A reference is actually an address of a variable which we will see in upcoming chapters.
2Arrays:
Arrays are ordered lists of scalars that you access with a numeric index which starts with 0. They are preceded by an "at" sign (@).
3Hashes:
Hashes are unordered sets of key/value pairs that you access using the keys as subscripts. They are preceded by a percent sign (%).

ADVERTISEMENTS

Numeric Literals

TypeValue
Integer1234
Negative integer-100
Floating point2000
Scientific notation16.12E14
Hexadecimal0xffff
Octal0577

ADVERTISEMENTS

String Literals

Escape sequenceMeaning
\\Backslash
\'Single quote
\"Double quote
\aAlert or bell
\bBackspace
\fForm feed
\nNewline
\rCarriage return
\tHorizontal tab
\vVertical tab
\0nnCreates Octal formatted numbers
\xnnCreates Hexideciamal formatted numbers
\cXControl characters, x may be any character
\uForce next character to uppercase
\lForce next character to lowercase
\UForce all following characters to uppercase
\LForce all following characters to lowercase
\QBackslash all following non-alphanumeric characters
\EEnd \U, \L, or \Q

Example

#!/usr/bin/perl

# This is case of interpolation.
$str = "Welcome to \n!";
print "$str\n";

# This is case of non-interpolation.
$str = 'Welcome to \n!';
print "$str\n";

# Only W will become upper case.
$str = "\uwelcome to !";
print "$str\n";

# Whole line will become capital.
$str = "\UWelcome to !";
print "$str\n";

# A portion of line will become capital.
$str = "Welcome to \U\E.com!"; 
print "$str\n";

# Backsalash non alpha-numeric including spaces.
$str = "\QWelcome to 's family";
print "$str\n";