Understanding Perl's Special Variables - Calling For A Translator (Page 10 of 11 )
Now, while the cryptic variable names discussed over the preceding pages
are frequently-used by experienced Perl developers. novice users might find
them a little disconcerting (at least in the beginning). That's why Perl
also provides for alternative syntax, in the form of longer, more-readable
English-language equivalents for the variables discussed previously.
In order to use the more-readable human-language names, simply add the line
use English;
to the top of your Perl script.
You should now be able to use Perl's longer names for the special variables
discussed in this tutorial, thereby adding greater readability to your
script. Here's a list mapping the special variables discussed above to
their longer names:
$_ = $ARG
$/ = $INPUT_RECORD_SEPARATOR
$\ = $OUTPUT_RECORD_SEPARATOR
$, = $OUTPUT_FIELD_SEPARATOR
$? = $CHILD_ERROR
$@ = $EVAL_ERROR
$! = $OS_ERROR
$< = $REAL_USER_ID
$> = $EFFECTIVE_USER_ID
$( = $REAL_GROUP_ID
$) = $EFFECTIVE_GROUP_ID
$. = $INPUT_LINE_NUMBER
$0 = $PROGRAM_NAME
$$ = $PROCESS_ID
$] = $PERL_VERSION
Consider the following variant of a previous example, which demonstrates
how they may be used:
#!/usr/bin/perl
use English;
# set record separator
$OUTPUT_RECORD_SEPARATOR=" ";
# print user and group
print "This script is running as " . getpwuid($EUID) . " who
belongs to the
following groups:";
foreach (split(" ", $))) { print scalar(getgrgid($ARG)); };
Next: End Zone >>
More Perl Articles
More By icarus, (c) Melonfire