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.
And that's about it for this tutorial. Over the preceding few pages, I introduced you to the following special variables in Perl:
$_ (the default variable)
$/ (the input record separator)
$\ (the output record separator)
$, (the output field separator)
@ARGV (the command-line argument array)
@_ (the subroutine argument array)
@INC (the include path array)
%ENV (the environment variable array)
$? and $! (the last error code)
$@ (the last error in an eval() block)
$<, $>, $) and $( (the real and effective UID/GIDs)
$. (the line number of an input file)
$ARGV (the name of an input file)
$0 (the name of the current script)
$$ (the process ID of the current script)
$[ (the Perl version number)
Of course, these are just some of the more commonly-used creatures you'll encounter in your travels through the Perl universe. Perl has a whole bunch more of these special variables which have not been discussed here - you can find them all in the "perlvar" manual page. Take a look for yourself, and until we meet again...stay healthy!
Note: Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article. YMMV!