X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlsub.pod;h=3619014e660e8c4a8688bf982ff4029bbf6dacdd;hb=dfa41748806263fb8b5d5fcb051bd36be96fe93c;hp=969d0ba0392b3cabf074bd30b6ea97b531c848da;hpb=ac90fb77766c098cd9f3441aa6691af8456d9c52;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlsub.pod b/pod/perlsub.pod index 969d0ba..3619014 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -588,6 +588,8 @@ separator. Notably, if you want to work with a brand new value of the default scalar $_, and avoid the potential problem listed above about $_ previously carrying a magic value, you should use C instead of C. +As of perl 5.9.1, you can also use the lexical form of C<$_> (declaring it +with C), which avoids completely this problem. =head3 Localization of elements of composite types @@ -1131,7 +1133,17 @@ The following functions would all be inlined: sub FLAG_MASK () { FLAG_FOO | FLAG_BAR } sub OPT_BAZ () { not (0x1B58 & FLAG_MASK) } - sub BAZ_VAL () { + + sub N () { int(OPT_BAZ) / 3 } + + sub FOO_SET () { 1 if FLAG_MASK & FLAG_FOO } + +Be aware that these will not be inlined; as they contain inner scopes, +the constant folding doesn't reduce them to a single constant: + + sub foo_set () { if (FLAG_MASK & FLAG_FOO) { 1 } } + + sub baz_val () { if (OPT_BAZ) { return 23; } @@ -1140,13 +1152,6 @@ The following functions would all be inlined: } } - sub N () { int(BAZ_VAL) / 3 } - BEGIN { - my $prod = 1; - for (1..N) { $prod *= $_ } - sub N_FACTORIAL () { $prod } - } - If you redefine a subroutine that was eligible for inlining, you'll get a mandatory warning. (You can use this warning to tell whether or not a particular subroutine is considered constant.) The warning is