Perl comes with a whole bunch of cryptically-named built-invariables, which clever Perl programmers exploit to reduce the number oflines of code in their scripts. This article examines some of the morecommonly-used special variable in Perl, with examples and illustrations ofhow they may be used.
A number of other special array variables also exist, in addition to @ARGV. One of the more commonly-used ones is the @INC variable, which sets up the "include paths" that Perl will look in when it encounters a call to require() or use(). This is analogous to the UNIX $PATH variable, which sets up default search paths for system binaries.
Let's take a look at this variable with the Data::Dumper module, used to "stringify" Perl data structure.
The difference between @INC and %INC is subtle but important - the former specifies the list of paths to search for files, while the latter specifies the files which have already been included in the current script, together with their paths.
There's also the %ENV hash, which contains a list of available environment variables.
Since %ENV is a hash, it's fairly easy to alter an environment setting - all you have to do is specify a new value for the corresponding hash key. Consider the following example, which shows you how:
#!/usr/bin/perl
# get value
print "Terminal is $ENV{'TERM'}\n";;
# change value
$ENV{'TERM'} = 'vt100';
# get new value
print "Terminal is now $ENV{'TERM'}\n";;