develooper Front page | perl.perl5.porters | Postings from June 2017

Re: lib/ puts references in %^H

Thread Previous | Thread Next
June 14, 2017 23:33
Re: lib/ puts references in %^H
Message ID:
demerphq wrote:
>But the value that was set at compile time does not appear to be set
>at run time.

Yes, that's correct.  %^H's scoping behaviour is driven by the scoping of
code being compiled, not the scoping of code being run.  That's because
the value of %^H is lexical state that's in effect for the code being
compiled, not for the code being run.  When you're not compiling anything,
%^H behaves essentially as an ordinary hash.

Since you didn't assign anything to $^H{t} during runtime of your test
program, of course it doesn't contain anything at runtime.  If you want
to see at runtime the $^H{t} value from compilation of the running code
(i.e., the lexical hint applying to the running code), you need to define
something like

	sub ht { ((caller(0))[10] // {})->{t} }

and print out its return value.

>I poked into this further and it seems to be true also fro $^H,

Same scoping behaviour.  caller item [8] to see at runtime the value
that it had at compile time of the running code.

>$ perl -le'use charnames (); use bytes (); sub translator {if ($^H &
>$bytes::hints_bits) { print "bytes" } else { print "unicode" } return
>"test" } BEGIN { $^H{charnames}= \&translator}; { use bytes; print
>"\N{TEST}" } '

$bytes::hints_bits is undefined.  You want $bytes::hint_bits, and with
that alteration this does print "bytes".


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About