Re: Call perl subroutine from $int->Eval

[email protected] ("Christopher Chavez") Fri, 6 Dec 2019 19:14:10 +0100
Newsgroups perl.tcltk
Message-ID <trinity-a27f1eac-8a90-40b2-8818-53f3905aea61-1575656050249@3c-app-mailcom-bs04>
Sent:=C2=A0Friday, December 06, 2019 at 11:30 AM
From:=C2=A0"welle ozean" <welleozean@googlemail=2Ecom>
To:=C2=A0"Christopher Chavez" <chrischavez@gmx=2Eus>
Subject:=C2=A0Re: Call perl subroutine from $int->Eval

> Thank you Christopher,

> this is very promising! But, I have no idea how to use it=2E Let's say I=
 have in my Perl code a subrutine called mySubrutine=2E How would I call it=
 from within the Eval Tcl code?

I would use something like:

$int->Eval(q/::perl::Eval {mySubroutine()} /)


I'm not an expert on how it works or if it has any significant limitations=
; it seems to work like Perl's built-in `eval` statement in the same scope =
as the `$int->Eval()`=2E I guess one thing to be careful of is which (if an=
y) string delimiters/escaping are used both in Perl and Tcl especially when=
ever `$variables` need to be specified, so that they refer to a Tcl or Perl=
 variable (or neither?)=2E For example if using a Perl variable, doing

my $variable =3D =2E=2E=2E;
$int->Eval(qq/::perl::Eval {mySubroutine($variable)} /);

might often behave the same as doing

my $variable =3D =2E=2E=2E;
$int->Eval(q/::perl::Eval {mySubroutine($variable)} /);

but I would prefer the latter usage so that the value of `$variable` isn't=
 translated (stringified) from Perl to Tcl and then back to Perl=2E


Christopher A=2E Chavez