++ to Corion and broquaint but just TMTOWTDI mode Inline::C:

#!/usr/bin/perl use Inline C; use strict; my $foo = "bar"; my $bar = [qw(foo bar baz)]; my $baz = {foo => "bar", baz => "quux"}; my $x = [ {foo => "bar", baz => "quux"}, {foo => "bar", baz => "quux"}, {foo => "bar", baz => "quux"}, ]; my $y = { foo => ["bar","quux"], baz => ["quux","bar"], }; print q("foo" -> ), describe("foo"), "\n"; print q(\\$foo -> ), describe(\$foo), "\n"; print q($bar -> ), describe($bar), "\n"; print q(\\$bar -> ), describe(\$bar), "\n"; print q($baz -> ), describe($baz), "\n"; print q(\\$baz -> ), describe(\$baz), "\n"; print q($x -> ), describe($x), "\n"; print q(\\$x -> ), describe(\$x), "\n"; print q($y -> ), describe($y), "\n"; print q(\\$y -> ), describe(\$y), "\n"; __END__ __C__ SV* describe( SV *var ) { SV *tmp; if( ! SvROK( var ) ) { return( newSVpvf( "%s", "S" ) ); } else { switch( SvTYPE( SvRV(var) ) ) { case SVt_PVAV: tmp = describe( av_pop( (AV *)SvRV(var) ) ); return( newSVpvf( "Ao%s", SvPV( tmp, PL_na ) ) ); case SVt_PVHV: tmp = describe( hv_iterval( (HV *)SvRV(var), hv_iternext( (HV *)SvRV(var) ) ) ); return( newSVpvf( "Ho%s", SvPV( tmp, PL_na ) ) ); case SVt_PVCV: return( newSVpvf( "%s", "C" ) ); case SVt_PVGV: return( newSVpvf( "%s", "G" ) ); case SVt_PVMG: return( newSVpvf( "%s", "B" ) ); case SVt_RV: tmp = describe( SvRV(var) ); return( newSVpvf( "r%s", SvPV( tmp, PL_na ) ) ); case SVt_IV: case SVt_NV: case SVt_PV: return( newSVpvf( "%s", "oS" ) ); default: return( newSVpvf( "?" ) ); } } }

-derby


In reply to Re: Checking whether two variables have the same structure by derby
in thread Checking whether two variables have the same structure by Corion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.