strict is a compile time pragma, it's effect is only on how the code in it's scope gets compiled, it doesn't do anything at runtime, so it will only be run once, even inside a loop. Actually now that I think of it any use statement only gets run once no matter where it is.
Before I realised that it's a use and so has no runtime effect, I did a bit of digging around in strict. The following might interest you.
If you look at
> perl -MO=Terse -e 'use strict;my @a;for my $f (@a){no strict "refs";
+print $$f}'
LISTOP (0x8225988) leave [1]
OP (0x831eec0) enter
COP (0x8245398) nextstate
OP (0x82258c8) padav [1]
COP (0x831ee58) nextstate
BINOP (0x831ee30) leaveloop
LOOP (0x8232a98) enteriter [2]
OP (0x82dc988) null [3]
UNOP (0x8232a70) null [141]
OP (0x823bc98) pushmark
OP (0x823bce8) padav [1]
UNOP (0x831ee10) null
LOGOP (0x82dc9e8) and
OP (0x82dc9a8) iter
LISTOP (0x82dc960) lineseq
COP (0x823c348) nextstate
LISTOP (0x823c300) print
OP (0x823c328) pushmark
UNOP (0x8225880) rv2sv
OP (0x82c1c20) padsv [2]
OP (0x82dc9c8) unstack
you can't see any sign of the no strict 'refs'. It's not in the op tree and therefore doesn't do anything at runtime.
If you look in more detail and compare the output of
perl -MO=Debug -e 'use strict;my @a;for my $f (@a){no strict "refs";pr
+int $$f}'
with
perl -MO=Debug -e 'use strict;my @a;for my $f (@a){print $$f}'
you will find (amongst other things) that the first contains
UNOP (0x83085c8)
op_next 0x830b190
op_sibling 0x0
op_ppaddr PL_ppaddr[OP_RV2SV]
op_targ 0
op_type 15
op_seq 7139
op_flags 6
op_private 1
op_first 0x8309088
and the second contains
UNOP (0x982ca28)
op_next 0x981f960
op_sibling 0x0
op_ppaddr PL_ppaddr[OP_RV2SV]
op_targ 0
op_type 15
op_seq 7128
op_flags 6
op_private 3
op_first 0x9835dd8
(I am far from an expert on these things by the way) RV2SV means Reference value 2 Scalar Value, this comes from $$f above. If you look in perl.h you'll find
#define HINT_STRICT_REFS 0x00000002 /* strict pragma */
This is used to turn on and off a flag in op_private.You can see that in the two debug dumps above, op_private is 1 for the no strict version and 3 for the all strict. This flag tells the interpreter whether the dereference should be checked for strictness when it's run. So here you can see exactly what the compile time effect of strict is.
|