Книга: 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.

Оглавление книги

Оглавление статьи/книги

Генерация: 0.626. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз