develooper Front page | perl.tcltk | Postings from December 2019

Re: Call perl subroutine from $int->Eval

Thread Previous
From:
Christopher Chavez
Date:
December 6, 2019 18:14
Subject:
Re: Call perl subroutine from $int->Eval
Message ID:
trinity-a27f1eac-8a90-40b2-8818-53f3905aea61-1575656050249@3c-app-mailcom-bs04
Sent: Friday, December 06, 2019 at 11:30 AM
From: "welle ozean" <welleozean@googlemail.com>
To: "Christopher Chavez" <chrischavez@gmx.us>
Subject: Re: Call perl subroutine from $int->Eval

> Thank you Christopher,

> this is very promising! But, I have no idea how to use it. Let's say I have in my Perl code a subrutine called mySubrutine. 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()`. I guess one thing to be careful of is which (if any) string delimiters/escaping are used both in Perl and Tcl especially whenever `$variables` need to be specified, so that they refer to a Tcl or Perl variable (or neither?). For example if using a Perl variable, doing

my $variable = ...;
$int->Eval(qq/::perl::Eval {mySubroutine($variable)} /);

might often behave the same as doing

my $variable = ...;
$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.


Christopher A. Chavez

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About