Movatterモバイル変換


[0]ホーム

URL:


variables /$^H
(source,CPAN)
#$^H

WARNING: This variable is strictly for internal use only. Its availability, behavior, and contents are subject to change without notice.

This variable contains compile-time hints for the Perl interpreter. At the end of compilation of a BLOCK the value of this variable is restored to the value when the interpreter started to compile the BLOCK.

Each time a statement completes being compiled, the current value of$^H is stored with that statement, and can later be retrieved via(caller($level))[8]. See"caller EXPR" in perlfunc.

When perl begins to parse any block construct that provides a lexical scope (e.g., eval body, required file, subroutine body, loop body, or conditional block), the existing value of$^H is saved, but its value is left unchanged. When the compilation of the block is completed, it regains the saved value. Between the points where its value is saved and restored, code that executes within BEGIN blocks is free to change the value of$^H.

This behavior provides the semantic of lexical scoping, and is used in, for instance, theuse strict pragma.

The contents should be an integer; different bits of it are used for different pragmatic flags. Here's an example:

sub add_100 { $^H |= 0x100 }sub foo {    BEGIN { add_100() }    bar->baz($boon);}

Consider what happens during execution of the BEGIN block. At this point the BEGIN block has already been compiled, but the body offoo() is still being compiled. The new value of$^H will therefore be visible only while the body offoo() is being compiled.

Substitution ofBEGIN { add_100() } block with:

BEGIN { require strict; strict->import('vars') }

demonstrates howuse strict 'vars' is implemented. Here's a conditional version of the same lexical pragma:

BEGIN {    require strict; strict->import('vars') if $condition}

This variable was added in Perl 5.003.

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2025 Movatter.jp