- Perl Basics
- Perl Home
- Perl Basic Syntax
- Perl Data Types
- Perl Variables
- Perl Scalars
- Perl Arrays
- Perl Hashes
- Perl If-Else
- Perl Loops
- Perl Operators
- Perl References
- Perl Subroutines
- Perl Formats
- Perl Date & Time
- Perl File I/O
- Perl Advanced
- Perl Directory
- Perl Regular Expressions
- Perl Special Variables
- Perl Socket Programming
- Perl Send E-mail
- Perl Object Oriented
- Perl Error Handling
- Perl CGI Programming
- Perl Database
- Perl Packages & Modules
- Perl Process Management
- Perl Test
- Perl Online Test
- Give Online Test
- All Test List
Perl Special Variables
Special variables are predefined having special meaning in perl. The special variables in perl, uses punctuation characters after the usual variable indicator using dollar ($), at (@), or percent (%) sign, like $_.
Perl Special Variable Example
The most commonly used special variable in perl is $_, contains the default input and pattern-searching string. Here is an example using special variable $_ in perl:
#!/usr/bin/perl foreach ('Deepak','Rajat','Ritesh') { print($_); print("\n"); }
When the above code is executed, it will produce the following output:
Deepak Rajat Ritesh
Perl Special Variable Types
There are the following types of special variables available in perl:
- Regular Expression Special Variables
- Filehandle Special Variables
- Global Scalar Special Variables
- Global Hash Special Variables
- Global Array Special Variables
- Global Special Constants
- Global Special Filehandles
Perl Global Scalar Special Variables
Here the following table lists all the scalar special variables available in perl.
Special Variable Symbol | Meaning |
---|---|
$_ | This special variable represents the default input and pattern-searching space |
$ | This special variable represents the current input line number of last filehandle that was read |
$/ | This special variable represents the input record separator, newline by default |
$, | This special variable represents the output field separator for the operator, print |
$\ | This special variable represents the output record separator for the operator, print |
$" | This special variable is similar to the "$," special variable, but in this case, it applies to the list values interpolated into a double-quoted strings. The default is a space |
$; | This special variable represents the subscript separator for the multidimensional array emulation. The default is "\034" |
$^L | This special variable is used to perform a formfeed. The default is "\f" |
$: | This special variable represents the current set of characters after which the string may be broken to fill the continuation fields (starting with symbol, ^) in a format. The default is "\n" |
$^A | This special variable represents the current value of the write accumulator for the format lines |
$# | This special variable contains the output format for the printed numbers |
$? | This special variable represents the status returned by the last pipe close, backtick command, or system operator |
$! | If this special variable used in a numeric context, yields the current value of the variable, errno, identifying the last system call error. If used in a string context, yields the corresponding system error string |
$@ | This special variable represents the perl syntax error message from the last eval command |
$$ | This special variable represents the pid of the perl process, running this script |
$< | This special variable represents the real user ID of this process |
$> | This special variable represents the user ID of this process |
$( | This special variable represents the real group ID of this process |
$) | This special variable represents the effective gid of this process |
$0 | This special variable contains the name of the file containing the perl script being executed |
$[ | This special variable represents the index of the first element in an array and of the first character in a substring. The default is 0 |
$] | This special variable returns the version plus patchlevel, divided by 1000 |
$^D | This special variable represents the current value of debugging flags |
$^E | This special variable represents an extended error message on various platforms |
$^F | This special variable represents the maximum system file descriptor, ordinarily 2 |
$^H | This special variable contains the internal compiler hints, enabled by certain pragmatic modules |
$^I | This special variable represents the current value of the inplace-edit extension |
$^M | This special variable represents the contents of $M can be used as an emergency memory pool in case if perl dies with an out-of-memory error. |
$^O | This special variable contains the name of the operating system that the current perl binary was compiled for |
$^P | This special variable represents the internal flag, the debugger clears so that it does not debug itself |
$^T | This special variable represents the time at which the script starts running, in seconds since the epoch |
$^W | This special variable represents the current value of the warning switch, either true or false |
$^X | This special variable represents the name that the perl binary itself was executed as |
Perl Global Array Special Variables
Here, the following table lists the global array special variables available in perl:
Special Variable | Meaning |
---|---|
@ARGV | This special variable represents the array containing the command line arguments intended for script |
@F | This special variable represents the array into which the input lines are split when the -a command line switch is given |
@INC | This special variable represents the array containing the list of places to look for the perl scripts to be evaluated by the do, require or use constructs |
Perl Global Hash Special Variables
Here, the following table lists the global hash special variables available in perl:
Special Variable | Meaning |
---|---|
%INC | This special variable represents the hash containing entries for the file name of each file, which has be included via do or require |
%SIG | This special variable represents the hash used to set the signal handlers for the various signals |
%ENV | This special variable represents the hash containing your current environment |
Perl Global Special Filehandles
Here, the following table lists the global special filehandles available in perl:
Special Variable | Meaning |
---|---|
ARGV | This special variable represents the special filehandle that iterates over the command line filenames in @ARGV |
STDIN | This special variable represents the special filehandle for the standard input in any package |
STDERR | This special variable represents the special filehandle for the standard error in any package |
STDOUT | This special variable represents the special filehandle for the standard output in any package |
_ | This special variable represents the special filehandle used to cache the information from the stat, lstat, last, or file test operator |
DATA | This special variable represents the special filehandle, refers to anything followed the _END_ toke in the file containing the script |
Perl Regular Expression Special Variables
Here the table given below, lists the regular expression special variables available in perl:
Special Variable | Meaning |
---|---|
$& | This special variable represents the string matched by the last successful pattern match |
$` | This special variable represents the string preceding whatever was matched by the last successful pattern match |
$' | This special variable represents the string following whatever was matched by the last successful pattern match |
$+ | This special variable represents the last bracket matched by the last search pattern |
Perl Filehandle Special Variables
Here the following table lists the filehandle special variables available in perl:
Special Variable | Meaning |
---|---|
$| | If this special variable set to non-zero, forces fflush(3) after every write or print on the currently selected output channel |
$% | This special variable represents the current page no. of the currently selected output channel |
$= | This special variable represents the current page length of the currently selected channel. The default is 60 |
$- | This special variable represents the number of lines left on the page of the currently selected output channel |
$~ | This special variable represents the name of the current report format for the currently selected channel. The default is the name of the filehandle |
$^ | This special variable represents the name of the current top of the page format for the currently selected output channel. |
« Previous Tutorial Next Tutorial »