#!/usr/bin/perl -w use strict; use B; my $foo = ' delicious'; my $string = 'abcde'; my %imahash = ( key => 3, foo => $foo, string => $string, ); print "Testing vec:\n"; ltype(\(vec($foo, 0, 32) = 0x5065726C)); print "Testing keys:\n"; ltype(\(keys %imahash = 5)); print "Testing pos:\n"; ltype(\(pos $string = 3)); print "Testing pos:\n"; ltype(\(pos $string = 5)); print "Testing substr EXPR, OFFSET:\n"; ltype(\substr($string, 2)); print "Testing substr EXPR, OFFSET, LENGTH:\n"; ltype(\substr($string, 1, 2)); print "Done.\n"; sub enter { #print "Press any key to continue...\n"; # Original post print "Press Enter to continue...\n"; # Update $_=; } sub lvalue { my $ref = shift; my $lref = B::svref_2object($ref); return undef if $lref !~ /PVLV/; my $value = $$ref; my $type = $lref->TYPE; my $targ = $lref->TARG; my $string = $lref->TARG->PV; my $offset = $lref->TARGOFF; my $length = $lref->TARGLEN; print 'TYPE: ', $type,"\n"; my $func; if ($type eq 'x') { $func = 'substr("'.$string.'",'.$offset.','.$length.');'; } if ($type eq '.') { print "magic type: ", $targ->MAGIC->TYPE,"\n"; # 'g' $func = 'pos "'.$string.'" = '.$value.';'; } if ($type eq 'k') { $func = 'keys %hash = ' . $targ->MAX . ';'; =comment print $targ->FILL,"\n"; print $targ->MAX,"\n"; print $targ->KEYS,"\n"; print $targ->NAME,"\n"; print $targ->RITER,"\n"; print $targ->PMROOT,"\n"; =cut my %newhash = $targ->ARRAY; print "key\tvalue\t\t\tclass\ttrue value\n"; foreach my $key (keys %newhash) { my $class = B::class($newhash{$key}); print "$key\t$newhash{$key}\t$class\t",$newhash{$key}->$class,"\n"; } } if ($type eq 'v') { $func = "vec('$string',$offset,$length) = $value;"; } return $func; } sub ltype { my $lvalue = shift; print '$$lvalue: ',$$lvalue,"\n"; print lvalue($lvalue),"\n"; enter(); }