in reply to Re^4: Using import to generate subroutines
in thread Using import to generate subroutines
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
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.> 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
If you look in more detail and compare the output of
withperl -MO=Debug -e 'use strict;my @a;for my $f (@a){no strict "refs";pr +int $$f}'
you will find (amongst other things) that the first containsperl -MO=Debug -e 'use strict;my @a;for my $f (@a){print $$f}'
and the second containsUNOP (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
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Using import to generate subroutines
by diotalevi (Canon) on Nov 24, 2004 at 23:35 UTC | |
by fergal (Chaplain) on Nov 25, 2004 at 00:17 UTC | |
by diotalevi (Canon) on Nov 25, 2004 at 00:24 UTC | |
|
Re^6: Using import to generate subroutines
by revdiablo (Prior) on Nov 25, 2004 at 01:04 UTC |