http://www.perlmonks.org?node_id=878687

patcat88 has asked for the wisdom of the Perl Monks concerning the following question:

How kosher is the following code? Is it acceptable to break open a scalar like this? is this documented in Perl's documentation? how often is this done? Does printing of references to scalars always produce SCALAR(0XBABABABA)? is that documented? is a reference being a dualvar documented?

I was looking at the source code of Acme::ESP and I saw the module breaking open a scalar. The rest of the code I can't figure out due to a lack of parenthesis.

I wrote this script the test out if Acme::ESP was really breaking open the scalars or not.

I am aware this is not 64 compliant, although using 'J' in the right places should fix that.

$c = 'camel'; $ref =\$c; print (($ref+0)."\n"); $ptr = pack( "L", $ref); @a = unpack('LLLL',unpack('P16',$ptr)); $flags = $a[2]; $h{'SVf_IOK'} = 0x00000100; # has valid public integer value */ $h{'SVf_NOK'} = 0x00000200; # has valid public numeric value */ $h{'SVf_POK'} = 0x00000400; # has valid public pointer value */ $h{'SVf_ROK'} = 0x00000800; # has a valid reference pointer */ $h{'SVp_IOK'} = 0x00001000; # has valid non-public integer value */ $h{'SVp_NOK'} = 0x00002000; # has valid non-public numeric value */ $h{'SVp_POK'} = 0x00004000; # has valid non-public pointer value */ $h{'SVp_SCREAM'} = 0x00008000; # has been studied? */ $h{'SVphv_CLONEABLE'} = 0x00008000; # PVHV (stashes) clone its objec +ts */ $h{'SVpgv_GP'} = 0x00008000; # GV has a valid GP */ $h{'SVprv_PCS_IMPORTED'} = 0x00008000; # RV is a proxy for a constan +t #subroutine in another package. Set the #CvIMPORTED_CV_ON() if it needs to be #expanded to a real GV */ $h{'SVs_PADSTALE'} = 0x00010000; # lexical has gone out of scope */ $h{'SVpad_STATE'} = 0x00010000; # pad name is a "state" var */ $h{'SVs_PADTMP'} = 0x00020000; # in use as tmp */ $h{'SVpad_TYPED'} = 0x00020000; # pad name is a Typed Lexical */ $h{'SVs_PADMY'} = 0x00040000; # in use a "my" variable */ $h{'SVpad_OUR'} = 0x00040000; # pad name is "our" instead of "my" */ $h{'SVs_TEMP'} = 0x00080000; # string is stealable? */ $h{'SVs_OBJECT'} = 0x00100000; # is "blessed" */ $h{'SVs_GMG'} = 0x00200000; # has magical get method */ $h{'SVs_SMG'} = 0x00400000; # has magical set method */ $h{'SVs_RMG'} = 0x00800000; # has random magical methods */ $h{'SVf_FAKE'} = 0x01000000; # 0: glob or lexical is just a copy #1: SV head arena wasn't malloc()ed #2: in conjunction with SVf_READONLY #marks a shared hash key scalar #(SvLEN == 0) or a copy on write #string (SvLEN != 0) [SvIsCOW(sv)] #3: For PVCV, whether CvUNIQUE(cv) # refers to an eval or once only # [CvEVAL(cv), CvSPECIAL(cv)] # 4: Whether the regexp pointer is in # fact an offset [SvREPADTMP(sv)] # 5: On a pad name SV, that slot in the # frame AV is a REFCNT'ed reference # to a lexical from "outside". */ $h{'SVphv_REHASH'} = 0x01000000; # 6: On a PVHV, hash values are b +eing #recalculated */ $h{'SVf_OOK'} = 0x02000000; # has valid offset value. For a PVHV thi +s #means that a hv_aux struct is present #after the main array */ $h{'SVf_BREAK'} = 0x04000000; # refcnt is artificially low - used by #SV's in final arena cleanup */ $h{'SVf_READONLY'} = 0x08000000; # may not be modified */ foreach(keys %h) { print "matched $_\n" if ($flags & $h{$_}); } print 'string depointered "'.unpack('P6',pack('L',$a[3])).'"'."\n";