注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Bioinformatics home

 
 
 

日志

 
 

perl 内置变量1 有空常读读  

2008-04-16 18:07:35|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

NAME
    perlvar - Perl predefined variables

DESCRIPTION
  Predefined Names
    The following names have special meaning to Perl. Most punctuation names
    have reasonable mnemonics, or analogs in the shells. Nevertheless, if
    you wish to use long variable names, you need only say

        use English;

    at the top of your program. This aliases all the short names to the long
    names in the current package. Some even have medium names, generally
    borrowed from awk. In general, it's best to use the

        use English '-no_match_vars';

    invocation if you don't need $PREMATCH, $MATCH, or $POSTMATCH, as it
    avoids a certain performance hit with the use of regular expressions.
    See English.

    Variables that depend on the currently selected filehandle may be set by
    calling an appropriate object method on the IO::Handle object, although
    this is less efficient than using the regular built-in variables.
    (Summary lines below for this contain the word HANDLE.) First you must
    say

        use IO::Handle;

    after which you may use either

        method HANDLE EXPR

    or more safely,

        HANDLE->method(EXPR)

    Each method returns the old value of the IO::Handle attribute. The
    methods each take an optional EXPR, which, if supplied, specifies the
    new value for the IO::Handle attribute in question. If not supplied,
    most methods do nothing to the current value--except for autoflush(),
    which will assume a 1 for you, just to be different.

    Because loading in the IO::Handle class is an expensive operation, you
    should learn how to use the regular built-in variables.

    A few of these variables are considered "read-only". This means that if
    you try to assign to this variable, either directly or indirectly
    through a reference, you'll raise a run-time exception.

    You should be very careful when modifying the default values of most
    special variables described in this document. In most cases you want to
    localize these variables before changing them, since if you don't, the
    change may affect other modules which rely on the default values of the
    special variables that you have changed. This is one of the correct ways
    to read the whole file at once:

        open my $fh, "foo" or die $!;
        local $/; # enable localized slurp mode
        my $content = <$fh>;
        close $fh;

    But the following code is quite bad:

        open my $fh, "foo" or die $!;
        undef $/; # enable slurp mode
        my $content = <$fh>;
        close $fh;

    since some other module, may want to read data from some file in the
    default "line mode", so if the code we have just presented has been
    executed, the global value of $/ is now changed for any other code
    running inside the same Perl interpreter.

    Usually when a variable is localized you want to make sure that this
    change affects the shortest scope possible. So unless you are already
    inside some short "{}" block, you should create one yourself. For
    example:

        my $content = '';
        open my $fh, "foo" or die $!;
        {
            local $/;
            $content = <$fh>;
        }
        close $fh;

    Here is an example of how your own code can go broken:

        for (1..5){
            nasty_break();
            print "$_ ";
        }
        sub nasty_break {
            $_ = 5;
            # do something with $_
        }

    You probably expect this code to print:

        1 2 3 4 5

    but instead you get:

        5 5 5 5 5

    Why? Because nasty_break() modifies $_ without localizing it first. The
    fix is to add local():

            local $_ = 5;

    It's easy to notice the problem in such a short example, but in more
    complicated code you are looking for trouble if you don't localize
    changes to the special variables.

    The following list is ordered by scalar variables first, then the
    arrays, then the hashes.

    $ARG
    $_      The default input and pattern-searching space. The following
            pairs are equivalent:

                while (<>) {...}    # equivalent only in while!
                while (defined($_ = <>)) {...}

                /^Subject:/
                $_ =~ /^Subject:/

                tr/a-z/A-Z/
                $_ =~ tr/a-z/A-Z/

                chomp
                chomp($_)

            Here are the places where Perl will assume $_ even if you don't
            use it:

            *  Various unary functions, including functions like ord() and
               int(), as well as the all file tests ("-f", "-d") except for
               "-t", which defaults to STDIN.

            *  Various list functions like print() and unlink().

            *  The pattern matching operations "m//", "s///", and "tr///"
               when used without an "=~" operator.

            *  The default iterator variable in a "foreach" loop if no other
               variable is supplied.

            *  The implicit iterator variable in the grep() and map()
               functions.

            *  The default place to put an input record when a "<FH>"
               operation's result is tested by itself as the sole criterion
               of a "while" test. Outside a "while" test, this will not
               happen.

            As $_ is a global variable, this may lead in some cases to
            unwanted side-effects. As of perl 5.9.1, you can now use a
            lexical version of $_ by declaring it in a file or in a block
            with "my". Moreover, declaring "our $_" restores the global $_
            in the current scope.

            (Mnemonic: underline is understood in certain operations.)

    $a
    $b      Special package variables when using sort(), see "sort" in
            perlfunc. Because of this specialness $a and $b don't need to be
            declared (using use vars, or our()) even when using the "strict
            'vars'" pragma. Don't lexicalize them with "my $a" or "my $b" if
            you want to be able to use them in the sort() comparison block
            or function.

    $<*digits*>
            Contains the subpattern from the corresponding set of capturing
            parentheses from the last pattern match, not counting patterns
            matched in nested blocks that have been exited already.
            (Mnemonic: like \digits.) These variables are all read-only and
            dynamically scoped to the current BLOCK.

    $MATCH
    $&      The string matched by the last successful pattern match (not
            counting any matches hidden within a BLOCK or eval() enclosed by
            the current BLOCK). (Mnemonic: like & in some editors.) This
            variable is read-only and dynamically scoped to the current
            BLOCK.

            The use of this variable anywhere in a program imposes a
            considerable performance penalty on all regular expression
            matches. See "BUGS".

            See "@-" for a replacement.

    ${^MATCH}
            This is similar to $& ($POSTMATCH) except that it does not incur
            the performance penalty associated with that variable, and is
            only guaranteed to return a defined value when the pattern was
            compiled or executed with the "/p" modifier.

    $PREMATCH
    $`      The string preceding whatever was matched by the last successful
            pattern match (not counting any matches hidden within a BLOCK or
            eval enclosed by the current BLOCK). (Mnemonic: "`" often
            precedes a quoted string.) This variable is read-only.

            The use of this variable anywhere in a program imposes a
            considerable performance penalty on all regular expression
            matches. See "BUGS".

            See "@-" for a replacement.

    ${^PREMATCH}
            This is similar to $` ($PREMATCH) except that it does not incur
            the performance penalty associated with that variable, and is
            only guaranteed to return a defined value when the pattern was
            compiled or executed with the "/p" modifier.

    $POSTMATCH
    $'      The string following whatever was matched by the last successful
            pattern match (not counting any matches hidden within a BLOCK or
            eval() enclosed by the current BLOCK). (Mnemonic: "'" often
            follows a quoted string.) Example:

                local $_ = 'abcdefghi';
                /def/;
                print "$`:$&:$'\n";         # prints abc:def:ghi

            This variable is read-only and dynamically scoped to the current
            BLOCK.

            The use of this variable anywhere in a program imposes a
            considerable performance penalty on all regular expression
            matches. See "BUGS".

            See "@-" for a replacement.

    ${^POSTMATCH}
            This is similar to $' ($POSTMATCH) except that it does not incur
            the performance penalty associated with that variable, and is
            only guaranteed to return a defined value when the pattern was
            compiled or executed with the "/p" modifier.

    $LAST_PAREN_MATCH
    $+      The text matched by the last bracket of the last successful
            search pattern. This is useful if you don't know which one of a
            set of alternative patterns matched. For example:

                /Version: (.*)|Revision: (.*)/ && ($rev = $+);

            (Mnemonic: be positive and forward looking.) This variable is
            read-only and dynamically scoped to the current BLOCK.

    $LAST_SUBMATCH_RESULT
    $^N     The text matched by the used group most-recently closed (i.e.
            the group with the rightmost closing parenthesis) of the last
            successful search pattern. (Mnemonic: the (possibly) Nested
            parenthesis that most recently closed.)

            This is primarily used inside "(?{...})" blocks for examining
            text recently matched. For example, to effectively capture text
            to a variable (in addition to $1, $2, etc.), replace "(...)"
            with

                 (?:(...)(?{ $var = $^N }))

            By setting and then using $var in this way relieves you from
            having to worry about exactly which numbered set of parentheses
            they are.

            This variable is dynamically scoped to the current BLOCK.

    @LAST_MATCH_END
    @+      This array holds the offsets of the ends of the last successful
            submatches in the currently active dynamic scope. $+[0] is the
            offset into the string of the end of the entire match. This is
            the same value as what the "pos" function returns when called on
            the variable that was matched against. The *n*th element of this
            array holds the offset of the *n*th submatch, so $+[1] is the
            offset past where $1 ends, $+[2] the offset past where $2 ends,
            and so on. You can use $#+ to determine how many subgroups were
            in the last successful match. See the examples given for the
            "@-" variable.

    %+      Similar to "@+", the "%+" hash allows access to the named
            capture buffers, should they exist, in the last successful match
            in the currently active dynamic scope.

            For example, $+{foo} is equivalent to $1 after the following
            match:

              'foo' =~ /(?<foo>foo)/;

            The keys of the "%+" hash list only the names of buffers that
            have captured (and that are thus associated to defined values).

            The underlying behaviour of "%+" is provided by the
            Tie::Hash::NamedCapture module.

            Note: "%-" and "%+" are tied views into a common internal hash
            associated with the last successful regular expression.
            Therefore mixing iterative access to them via "each" may have
            unpredictable results. Likewise, if the last successful match
            changes, then the results may be surprising.

    HANDLE->input_line_number(EXPR)
    $INPUT_LINE_NUMBER
    $NR
    $.      Current line number for the last filehandle accessed.

            Each filehandle in Perl counts the number of lines that have
            been read from it. (Depending on the value of $/, Perl's idea of
            what constitutes a line may not match yours.) When a line is
            read from a filehandle (via readline() or "<>"), or when tell()
            or seek() is called on it, $. becomes an alias to the line
            counter for that filehandle.

            You can adjust the counter by assigning to $., but this will not
            actually move the seek pointer. *Localizing $. will not localize
            the filehandle's line count*. Instead, it will localize perl's
            notion of which filehandle $. is currently aliased to.

            $. is reset when the filehandle is closed, but not when an open
            filehandle is reopened without an intervening close(). For more
            details, see "I/O Operators" in perlop. Because "<>" never does
            an explicit close, line numbers increase across ARGV files (but
            see examples in "eof" in perlfunc).

            You can also use "HANDLE->input_line_number(EXPR)" to access the
            line counter for a given filehandle without having to worry
            about which handle you last accessed.

            (Mnemonic: many programs use "." to mean the current line
            number.)

    IO::Handle->input_record_separator(EXPR)
    $INPUT_RECORD_SEPARATOR
    $RS
    $/      The input record separator, newline by default. This influences
            Perl's idea of what a "line" is. Works like awk's RS variable,
            including treating empty lines as a terminator if set to the
            null string. (An empty line cannot contain any spaces or tabs.)
            You may set it to a multi-character string to match a
            multi-character terminator, or to "undef" to read through the
            end of file. Setting it to "\n\n" means something slightly
            different than setting to "", if the file contains consecutive
            empty lines. Setting to "" will treat two or more consecutive
            empty lines as a single empty line. Setting to "\n\n" will
            blindly assume that the next input character belongs to the next
            paragraph, even if it's a newline. (Mnemonic: / delimits line
            boundaries when quoting poetry.)

                local $/;           # enable "slurp" mode
                local $_ = <FH>;    # whole file now here
                s/\n[ \t]+/ /g;

            Remember: the value of $/ is a string, not a regex. awk has to
            be better for something. :-)

            Setting $/ to a reference to an integer, scalar containing an
            integer, or scalar that's convertible to an integer will attempt
            to read records instead of lines, with the maximum record size
            being the referenced integer. So this:

                local $/ = \32768; # or \"32768", or \$var_containing_32768
                open my $fh, $myfile or die $!;
                local $_ = <$fh>;

            will read a record of no more than 32768 bytes from FILE. If
            you're not reading from a record-oriented file (or your OS
            doesn't have record-oriented files), then you'll likely get a
            full chunk of data with every read. If a record is larger than
            the record size you've set, you'll get the record back in
            pieces. Trying to set the record size to zero or less will cause
            reading in the (rest of the) whole file.

            On VMS, record reads are done with the equivalent of "sysread",
            so it's best not to mix record and non-record reads on the same
            file. (This is unlikely to be a problem, because any file you'd
            want to read in record mode is probably unusable in line mode.)
            Non-VMS systems do normal I/O, so it's safe to mix record and
            non-record reads of a file.

            See also "Newlines" in perlport. Also see $..

    HANDLE->autoflush(EXPR)
    $OUTPUT_AUTOFLUSH
    $|      If set to nonzero, forces a flush right away and after every
            write or print on the currently selected output channel. Default
            is 0 (regardless of whether the channel is really buffered by
            the system or not; $| tells you only whether you've asked Perl
            explicitly to flush after each write). STDOUT will typically be
            line buffered if output is to the terminal and block buffered
            otherwise. Setting this variable is useful primarily when you
            are outputting to a pipe or socket, such as when you are running
            a Perl program under rsh and want to see the output as it's
            happening. This has no effect on input buffering. See "getc" in
            perlfunc for that. (Mnemonic: when you want your pipes to be
            piping hot.)

    IO::Handle->output_field_separator EXPR
    $OUTPUT_FIELD_SEPARATOR
    $OFS
    $,      The output field separator for the print operator. If defined,
            this value is printed between each of print's arguments. Default
            is "undef". (Mnemonic: what is printed when there is a "," in
            your print statement.)

    IO::Handle->output_record_separator EXPR
    $OUTPUT_RECORD_SEPARATOR
    $ORS
    $\      The output record separator for the print operator. If defined,
            this value is printed after the last of print's arguments.
            Default is "undef". (Mnemonic: you set $\ instead of adding "\n"
            at the end of the print. Also, it's just like $/, but it's what
            you get "back" from Perl.)

    $LIST_SEPARATOR
    $"      This is like $, except that it applies to array and slice values
            interpolated into a double-quoted string (or similar interpreted
            string). Default is a space. (Mnemonic: obvious, I think.)

    $SUBSCRIPT_SEPARATOR
    $SUBSEP
    $;      The subscript separator for multidimensional array emulation. If
            you refer to a hash element as

                $foo{$a,$b,$c}

            it really means

                $foo{join($;, $a, $b, $c)}

            But don't put

                @foo{$a,$b,$c}      # a slice--note the @

            which means

                ($foo{$a},$foo{$b},$foo{$c})

            Default is "\034", the same as SUBSEP in awk. If your keys
            contain binary data there might not be any safe value for $;.
            (Mnemonic: comma (the syntactic subscript separator) is a
            semi-semicolon. Yeah, I know, it's pretty lame, but $, is
            already taken for something more important.)

            Consider using "real" multidimensional arrays as described in
            perllol.

    HANDLE->format_page_number(EXPR)
    $FORMAT_PAGE_NUMBER
    $%      The current page number of the currently selected output
            channel. Used with formats. (Mnemonic: % is page number in
            nroff.)

    HANDLE->format_lines_per_page(EXPR)
    $FORMAT_LINES_PER_PAGE
    $=      The current page length (printable lines) of the currently
            selected output channel. Default is 60. Used with formats.
            (Mnemonic: = has horizontal lines.)

    HANDLE->format_lines_left(EXPR)
    $FORMAT_LINES_LEFT
    $-      The number of lines left on the page of the currently selected
            output channel. Used with formats. (Mnemonic: lines_on_page -
            lines_printed.)

    @LAST_MATCH_START
    @-      $-[0] is the offset of the start of the last successful match.
            "$-["*n*"]" is the offset of the start of the substring matched
            by *n*-th subpattern, or undef if the subpattern did not match.

            Thus after a match against $_, $& coincides with "substr $_,
            $-[0], $+[0] - $-[0]". Similarly, $*n* coincides with "substr
            $_, $-[n], $+[n] - $-[n]" if $-[n] is defined, and $+ coincides
            with "substr $_, $-[$#-], $+[$#-] - $-[$#-]". One can use $#- to
            find the last matched subgroup in the last successful match.
            Contrast with $#+, the number of subgroups in the regular
            expression. Compare with "@+".

            This array holds the offsets of the beginnings of the last
            successful submatches in the currently active dynamic scope.
            $-[0] is the offset into the string of the beginning of the
            entire match. The *n*th element of this array holds the offset
            of the *n*th submatch, so $-[1] is the offset where $1 begins,
            $-[2] the offset where $2 begins, and so on.

            After a match against some variable $var:

            $` is the same as "substr($var, 0, $-[0])"
            $& is the same as "substr($var, $-[0], $+[0] - $-[0])"
            $' is the same as "substr($var, $+[0])"
            $1 is the same as "substr($var, $-[1], $+[1] - $-[1])"
            $2 is the same as "substr($var, $-[2], $+[2] - $-[2])"
            $3 is the same as "substr($var, $-[3], $+[3] - $-[3])"

    %-      Similar to "%+", this variable allows access to the named
            capture buffers in the last successful match in the currently
            active dynamic scope. To each capture buffer name found in the
            regular expression, it associates a reference to an array
            containing the list of values captured by all buffers with that
            name (should there be several of them), in the order where they
            appear.

            Here's an example:

                if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) {
                    foreach my $bufname (sort keys %-) {
                        my $ary = $-{$bufname};
                        foreach my $idx (0..$#$ary) {
                            print "\$-{$bufname}[$idx] : ",
                                  (defined($ary->[$idx]) ? "'$ary->[$idx]'" : "undef"),
                                  "\n";
                        }
                    }
                }

            would print out:

                $-{A}[0] : '1'
                $-{A}[1] : '3'
                $-{B}[0] : '2'
                $-{B}[1] : '4'

            The keys of the "%-" hash correspond to all buffer names found
            in the regular expression.

            The behaviour of "%-" is implemented via the
            Tie::Hash::NamedCapture module.

            Note: "%-" and "%+" are tied views into a common internal hash
            associated with the last successful regular expression.
            Therefore mixing iterative access to them via "each" may have
            unpredictable results. Likewise, if the last successful match
            changes, then the results may be surprising.

    HANDLE->format_name(EXPR)
    $FORMAT_NAME
    $~      The name of the current report format for the currently selected
            output channel. Default is the name of the filehandle.
            (Mnemonic: brother to $^.)

    HANDLE->format_top_name(EXPR)
    $FORMAT_TOP_NAME
    $^      The name of the current top-of-page format for the currently
            selected output channel. Default is the name of the filehandle
            with _TOP appended. (Mnemonic: points to top of page.)

    IO::Handle->format_line_break_characters EXPR
    $FORMAT_LINE_BREAK_CHARACTERS
    $:      The current set of characters after which a string may be broken
            to fill continuation fields (starting with ^) in a format.
            Default is " \n-", to break on whitespace or hyphens. (Mnemonic:
            a "colon" in poetry is a part of a line.)

    IO::Handle->format_formfeed EXPR
    $FORMAT_FORMFEED
    $^L     What formats output as a form feed. Default is \f.

    $ACCUMULATOR
    $^A     The current value of the write() accumulator for format() lines.
            A format contains formline() calls that put their result into
            $^A. After calling its format, write() prints out the contents
            of $^A and empties. So you never really see the contents of $^A
            unless you call formline() yourself and then look at it. See
            perlform and "formline()" in perlfunc.

    $CHILD_ERROR
    $?      The status returned by the last pipe close, backtick (``)
            command, successful call to wait() or waitpid(), or from the
            system() operator. This is just the 16-bit status word returned
            by the traditional Unix wait() system call (or else is made up
            to look like it). Thus, the exit value of the subprocess is
            really ("$? >> 8"), and "$? & 127" gives which signal, if any,
            the process died from, and "$? & 128" reports whether there was
            a core dump. (Mnemonic: similar to sh and ksh.)

            Additionally, if the "h_errno" variable is supported in C, its
            value is returned via $? if any "gethost*()" function fails.

            If you have installed a signal handler for "SIGCHLD", the value
            of $? will usually be wrong outside that handler.

            Inside an "END" subroutine $? contains the value that is going
            to be given to "exit()". You can modify $? in an "END"
            subroutine to change the exit status of your program. For
            example:

                END {
                    $? = 1 if $? == 255;  # die would make it 255
                }

            Under VMS, the pragma "use vmsish 'status'" makes $? reflect the
            actual VMS exit status, instead of the default emulation of
            POSIX status; see "$?" in perlvms for details.

            Also see "Error Indicators".

    ${^CHILD_ERROR_NATIVE}
            The native status returned by the last pipe close, backtick (``)
            command, successful call to wait() or waitpid(), or from the
            system() operator. On POSIX-like systems this value can be
            decoded with the WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG,
            WIFSTOPPED, WSTOPSIG and WIFCONTINUED functions provided by the
            POSIX module.

            Under VMS this reflects the actual VMS exit status; i.e. it is
            the same as $? when the pragma "use vmsish 'status'" is in
            effect.

    ${^ENCODING}
            The *object reference* to the Encode object that is used to
            convert the source code to Unicode. Thanks to this variable your
            perl script does not have to be written in UTF-8. Default is
            *undef*. The direct manipulation of this variable is highly
            discouraged.

    $OS_ERROR
    $ERRNO
    $!      If used numerically, yields the current value of the C "errno"
            variable, or in other words, if a system or library call fails,
            it sets this variable. This means that the value of $! is
            meaningful only *immediately* after a failure:

                if (open(FH, $filename)) {
                    # Here $! is meaningless.
                    ...
                } else {
                    # ONLY here is $! meaningful.
                    ...
                    # Already here $! might be meaningless.
                }
                # Since here we might have either success or failure,
                # here $! is meaningless.

            In the above *meaningless* stands for anything: zero, non-zero,
            "undef". A successful system or library call does not set the
            variable to zero.

            If used as a string, yields the corresponding system error
            string. You can assign a number to $! to set *errno* if, for
            instance, you want "$!" to return the string for error *n*, or
            you want to set the exit value for the die() operator.
            (Mnemonic: What just went bang?)

            Also see "Error Indicators".

    %OS_ERROR
    %ERRNO
    %!      Each element of "%!" has a true value only if $! is set to that
            value. For example, $!{ENOENT} is true if and only if the
            current value of $! is "ENOENT"; that is, if the most recent
            error was "No such file or directory" (or its moral equivalent:
            not all operating systems give that exact error, and certainly
            not all languages). To check if a particular key is meaningful
            on your system, use "exists $!{the_key}"; for a list of legal
            keys, use "keys %!". See Errno for more information, and also
            see above for the validity of $!.

    $EXTENDED_OS_ERROR
    $^E     Error information specific to the current operating system. At
            the moment, this differs from $! under only VMS, OS/2, and Win32
            (and for MacPerl). On all other platforms, $^E is always just
            the same as $!.

            Under VMS, $^E provides the VMS status value from the last
            system error. This is more specific information about the last
            system error than that provided by $!. This is particularly
            important when $! is set to EVMSERR.

            Under OS/2, $^E is set to the error code of the last call to
            OS/2 API either via CRT, or directly from perl.

            Under Win32, $^E always returns the last error information
            reported by the Win32 call "GetLastError()" which describes the
            last error from within the Win32 API. Most Win32-specific code
            will report errors via $^E. ANSI C and Unix-like calls set
            "errno" and so most portable Perl code will report errors via
            $!.

            Caveats mentioned in the description of $! generally apply to
            $^E, also. (Mnemonic: Extra error explanation.)

            Also see "Error Indicators".

    $EVAL_ERROR
    $@      The Perl syntax error message from the last eval() operator. If
            $@ is the null string, the last eval() parsed and executed
            correctly (although the operations you invoked may have failed
            in the normal fashion). (Mnemonic: Where was the syntax error
            "at"?)

            Warning messages are not collected in this variable. You can,
            however, set up a routine to process warnings by setting
            $SIG{__WARN__} as described below.

            Also see "Error Indicators".

    $PROCESS_ID
    $PID
    $$      The process number of the Perl running this script. You should
            consider this variable read-only, although it will be altered
            across fork() calls. (Mnemonic: same as shells.)

            Note for Linux users: on Linux, the C functions "getpid()" and
            "getppid()" return different values from different threads. In
            order to be portable, this behavior is not reflected by $$,
            whose value remains consistent across threads. If you want to
            call the underlying "getpid()", you may use the CPAN module
            "Linux::Pid".

    $REAL_USER_ID
    $UID
    $<      The real uid of this process. (Mnemonic: it's the uid you came
            *from*, if you're running setuid.) You can change both the real
            uid and the effective uid at the same time by using
            POSIX::setuid(). Since changes to $< require a system call,
            check $! after a change attempt to detect any possible errors.

    $EFFECTIVE_USER_ID
    $EUID
    $>      The effective uid of this process. Example:

                $< = $>;            # set real to effective uid
                ($<,$>) = ($>,$<);  # swap real and effective uid

            You can change both the effective uid and the real uid at the
            same time by using POSIX::setuid(). Changes to $> require a
            check to $! to detect any possible errors after an attempted
            change.

            (Mnemonic: it's the uid you went *to*, if you're running
            setuid.) $< and $> can be swapped only on machines supporting
            setreuid().

    $REAL_GROUP_ID
    $GID
    $(      The real gid of this process. If you are on a machine that
            supports membership in multiple groups simultaneously, gives a
            space separated list of groups you are in. The first number is
            the one returned by getgid(), and the subsequent ones by
            getgroups(), one of which may be the same as the first number.

            However, a value assigned to $( must be a single number used to
            set the real gid. So the value given by $( should *not* be
            assigned back to $( without being forced numeric, such as by
            adding zero. Note that this is different to the effective gid
            ($)) which does take a list.

            You can change both the real gid and the effective gid at the
            same time by using POSIX::setgid(). Changes to $( require a
            check to $! to detect any possible errors after an attempted
            change.

            (Mnemonic: parentheses are used to *group* things. The real gid
            is the group you *left*, if you're running setgid.)

  

  评论这张
 
阅读(457)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017