Книга: Fedora™ Unleashed, 2008 edition
Special Variables
Special Variables
Perl has a wide variety of special variables, which usually look like punctuation — $_
, $!
, and $]
— and are all extremely useful for shorthand code. $_
is the default variable, $!
is the error message returned by the operating system, and $]
is the Perl version number.
$_
is perhaps the most useful of these, and you will see that variable used often in this chapter. $_
is the Perl default variable, which is used when no argument is specified. For example, the following two statements are equivalent:
chomp;
chomp($_);
The following loops are equivalent:
for $cow (@cattle) {
print "$cow says moo.n";
}
for (@cattle) {
print "$_ says moo.n";
}
For a complete listing of the special variables, you should see the perlvar
document that comes with your Perl distribution (such as in the perlvar
manual page), or you can go online to http://theoryx5.uwinnipeg.ca/CPAN/perl/pod/perlvar.html.
- Perl Variables and Data Structures
- Special String Constants
- Special Operators
- Built-In Variables
- Special Characters
- Dynamic, a.k.a. Special, Variables
- Appendix A. Detailed explanations of special commands
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces
- Using Environment Variables
- Special Mail Delivery Agents
- Class and Object Variables
- Variables