#! perl -slw use strict; use Inline C => << '__C__', NAME => 'test', CLEAN_AFTER_BUILD => 0; #include SV* test( SV *a, SV *b ) { if( SvREADONLY( a ) ) // Readonly? Take a copy. a = newSVpv( SvPVX( a ), 0 ); if( !SvPOK( a ) && ( SvNOK( a ) || SvIOK( a ) || SvUOK( a ) ) ) // numeric SvPV_nolen( a ); // Force a string rep if( !SvPOK( a ) ) // Still nothing, must be undef? sv_setpv( a, "" ); // Make it the null string to stop (one possible) // Use of uninitialized value in subroutine entry from sv_catsv sv_catsv( a, b ); return SvREFCNT_inc( a ); // Why do I need to increment the ref count? } __C__ print test( 'bill', 'fred' ); my( $p, $q ) = ( 'fred' ); print test( $q, $p ); $q = 'bill'; print test( $q, $p ); $q = 1; print test( $q, $p ); $p = 1; print test( $q, $p ); __END__ c:\test>test billfred fred billfred 1fred 1fred1 #### SV* test( SV *a, SV *b ) { if( SvREADONLY( a ) ) a = newSVpv( SvPVX( a ), 0 ); else SvREFCNT_inc( a ); if( !SvOK( a ) ) sv_setpvn( a, "", 0 ); sv_catsv( a, b ); return a; }