void foo(SV * sv) { if(sv) { printf("%s\n", SvPV_nolen(sv)); } } void bar(SV * sv) { printf ("%i\n", SvPOK(sv)); } Mytest2::foo('asdf'); # prints asdf Mytest2::bar(1); # prints 0 Mytest2::foo(1); # Segmentation Fault #### void foo(SV * sv) { char buf[1024]; switch(SvTYPE(sv)) { case SVt_IV: snprintf(buf, sizeof(buf), "%s\n", SvPV(sv)); break; case SVt_PV: snprintf(buf, sizeof(buf), "%d\n", SvIV(sv)); break; case SVt_NV: snprintf(buf, sizeof(buf), "%f\n", SvNV(sv)); break; ... handle scalar refs here ... } printf("%s\n", buf); }