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

I'm trying to source some external tcl libraries inside my perl script which uses Inline::Tcl so that I have access to the tcl functions. I get the following error no matter what name or path I use:
"Couldn't parse your Tcl code."
The library file is used by other scripts that work well so I assume there is nothing wrong with it. Is there a better way to debug this or is my syntax incorrect?
#!/usr/bin/perl use Inline Tcl => <<END; source "smb.tcl" END $result = SmartbitsSocketLink();

Replies are listed 'Best First'.
Re: Perl, Tcl and Inline::Tcl loading libraries
by Anonymous Monk on Aug 19, 2009 at 23:41 UTC
    Start up tclsh and try source "smb.tcl" in there.
      Thank you!! Looks like the problem is related to a non-compiled library. I have no idea how to solve that problem but it probably isn't for this forum.
      prompt#tclsh smb.tcl couldn't load file "libtclStruct.so": libtclStruct.so: wrong ELF class +: ELFCLASS32
      Ok, I got the library issues figured out but now I do this and still get the same error. The tclsh shows no errors with the library and as you can see the perl inline tcl code is just one line:

      Couldn't parse your Tcl code. at ./test.pl line 5 BEGIN failed--compilation aborted at ./test.pl line 7.

      host:/usr/local/smartbits\_# tclsh % source "smb.tcl" # NO ERRORS HERE % exit

      #!/usr/bin/perl use Inline Tcl => <<END; source "smb.tcl" END my $result = SmartbitsSocketLink("1.1.1.1");
        You know what, this is getting boring :)
        diff -ruN Inline-Tcl-0.09/Changes Inline-Tcl-0.09-new/Changes --- Inline-Tcl-0.09/Changes 2001-05-28 10:30:35.000000000 -0700 +++ Inline-Tcl-0.09-new/Changes 2009-08-21 00:01:12.203125000 -0700 @@ -1,4 +1,5 @@ Revision history for Inline::Tcl +0.091: [Anonymous Monk] added $Inline::Tcl::LASTERROR (and t/03error. +t ) 0.09: Initial release compatible with Inline-0.40 Removed debugging files mydebug.h and test.sh Files Inline-Tcl-0.09/Inline-Tcl-0.091.tar.gz and Inline-Tcl-0.09-new/ +Inline-Tcl-0.091.tar.gz differ diff -ruN Inline-Tcl-0.09/Makefile.PL Inline-Tcl-0.09-new/Makefile.PL --- Inline-Tcl-0.09/Makefile.PL 2001-05-14 12:46:29.000000000 -0700 +++ Inline-Tcl-0.09-new/Makefile.PL 2009-08-21 00:10:59.921875000 - +0700 @@ -57,7 +57,7 @@ my $lib = prompt(join("\n",("Found these TCL libraries: ", map {$num++ . ". $_"} @tcl_libs_found))."\nUse? (or e +nter alternative)", "1") if @tcl_libs_found; -$lib = prompt ("Please enter the TCL library.", "") +$lib = prompt ("Please enter the TCL library.", scalar glob "C:/Tcl/l +ib/tcl8*.lib") unless @tcl_libs_found; $lib = $tcl_libs_found[$lib-1] if $lib =~ /^\d+$/; @@ -69,7 +69,7 @@ my $inc = prompt(join("\n",("Found these TCL include dirs: ", map {$num++ . ". $_"} @tcl_incs_found))."\nUse? (or e +nter alternative)", "1") if @tcl_incs_found; -$inc = prompt ("Please enter the TCL include directory.", "") +$inc = prompt ("Please enter the TCL include directory.", "C:/Tcl/inc +lude") unless @tcl_incs_found; $inc = $tcl_incs_found[$inc-1] if $inc =~ /^\d+$/; diff -ruN Inline-Tcl-0.09/MANIFEST Inline-Tcl-0.09-new/MANIFEST --- Inline-Tcl-0.09/MANIFEST 2001-05-27 19:13:14.000000000 -0700 +++ Inline-Tcl-0.09-new/MANIFEST 2009-08-20 23:51:09.812500000 -070 +0 @@ -9,4 +9,5 @@ t/00init.t t/01aaa.t t/02bbb.t +t/03error.t t/a1.pl diff -ruN Inline-Tcl-0.09/t/03error.t Inline-Tcl-0.09-new/t/03error.t --- Inline-Tcl-0.09/t/03error.t 1969-12-31 16:00:00.000000000 -0800 +++ Inline-Tcl-0.09-new/t/03error.t 2009-08-21 00:02:12.328125000 - +0700 @@ -0,0 +1,15 @@ + +use Inline Config => DIRECTORY => './blib_test'; + +use Test::More tests => 1; + +my $ok = eval { +Inline->import(Tcl => <<END); + proc ASDF { valval { + } +END + + 1 +}; + +ok( ! defined $ok , $@); # Couldn't parse your Tcl code: missing clos +e-brace diff -ruN Inline-Tcl-0.09/Tcl.pm Inline-Tcl-0.09-new/Tcl.pm --- Inline-Tcl-0.09/Tcl.pm 2001-05-27 19:06:02.000000000 -0700 +++ Inline-Tcl-0.09-new/Tcl.pm 2009-08-20 23:59:34.640625000 -0700 @@ -1,7 +1,7 @@ package Inline::Tcl; use strict; -$Inline::Tcl::VERSION = '0.09'; +$Inline::Tcl::VERSION = '0.091'; require Inline; require DynaLoader; @@ -15,6 +15,9 @@ @EXPORT_OK = qw(eval_tcl); + +$Inline::Tcl::LASTERROR = undef; + #==================================================================== +========== # Load (and initialize) the Tcl Interpreter #==================================================================== +========== @@ -156,7 +159,7 @@ my $o = shift; return if $o->{Tcl}{built}; my $result = _eval_tcl($o->{API}{code}); - croak "Couldn't parse your Tcl code.\n" + croak "Couldn't parse your Tcl code: $Inline::Tcl::LASTERROR\n" unless $result; my %namespace = _Inline_parse_tcl_namespace(); diff -ruN Inline-Tcl-0.09/Tcl.xs Inline-Tcl-0.09-new/Tcl.xs --- Inline-Tcl-0.09/Tcl.xs 2001-05-27 19:14:37.000000000 -0700 +++ Inline-Tcl-0.09-new/Tcl.xs 2009-08-20 23:38:35.781250000 -0700 @@ -105,6 +105,7 @@ int result; CODE: result = Tcl_Eval(interp,x); + sv_setpv(get_sv("Inline::Tcl::LASTERROR", TRUE), Tcl_GetStringRes +ult(interp)); RETVAL = (result == TCL_OK); OUTPUT: RETVAL @@ -145,6 +146,7 @@ Tcl_Eval(interp, command); result = Tcl_GetStringResult(interp); + sv_setpv(get_sv("Inline::Tcl::LASTERROR", TRUE), result); ret = Tcl2Pl(result, PKG); free(command);
        To apply this patch cd to Inline-Tcl-0.09 and run patch -p1 -N < Inline-Tcl-0.09-new.patch

        This should give you an actual error message like tclsh does.