PERL TUTORIALS - Perl Data Types
Perl Data Types
ADVERTISEMENTS
S.N. | Types and Description |
---|---|
1 | Scalar: 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. |
2 | Arrays: Arrays are ordered lists of scalars that you access with a numeric index which starts with 0. They are preceded by an "at" sign (@). |
3 | Hashes: 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
Type | Value |
---|---|
Integer | 1234 |
Negative integer | -100 |
Floating point | 2000 |
Scientific notation | 16.12E14 |
Hexadecimal | 0xffff |
Octal | 0577 |
ADVERTISEMENTS
String Literals
Escape sequence | Meaning |
---|---|
\\ | Backslash |
\' | Single quote |
\" | Double quote |
\a | Alert or bell |
\b | Backspace |
\f | Form feed |
\n | Newline |
\r | Carriage return |
\t | Horizontal tab |
\v | Vertical tab |
\0nn | Creates Octal formatted numbers |
\xnn | Creates Hexideciamal formatted numbers |
\cX | Control characters, x may be any character |
\u | Force next character to uppercase |
\l | Force next character to lowercase |
\U | Force all following characters to uppercase |
\L | Force all following characters to lowercase |
\Q | Backslash all following non-alphanumeric characters |
\E | End \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";