Global 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 handlers for various signals.

Global Special Filehandles

ARGVThe special filehandle that iterates over command line filenames in @ARGV. Usually written as the null filehandle in <>.
STDERRThe special filehandle for standard error in any package.
STDINThe special filehandle for standard input in any package.
STDOUTThe special filehandle for standard output in any package.
DATAThe special filehandle that refers to anything following the __END__ token in the file containing the script. Or, the special filehandle for anything following the __DATA__ token in a required file, as long as you're reading data in the same package __DATA__ was found in.
_ (underscore)The special filehandle used to cache the information from the last stat, lstat, or file test operator.

Global Special Constants

__END__Indicates the logical end of your program. Any following text is ignored, but may be read via the DATA filehandle.
__FILE__Represents the filename at the point in your program where it's used. Not interpolated into strings.
__LINE__Represents the current line number. Not interpolated into strings.
__PACKAGE__Represents the current package name at compile time, or undefined if there is no current package. Not interpolated into strings.

Updated on: 29-Nov-2019


Kickstart Your Career

Get certified by completing the course

Get Started