emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] evaluation of perl in babel


From: Achim Gratz
Subject: Re: [O] evaluation of perl in babel
Date: Sun, 24 Feb 2013 23:09:04 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.93 (gnu/linux)

D M German writes:
> There are some bugs. For example, the interpretation of :results table,
> vector and list.

You may misunderstand some things, or I don't understand what you are
asking.  It is (at least currently) the responsibility of the Perl
program (or any other Babel language) to deliver the result in such a
way that it can be interpreted correctly by the result type chosen (in
other word, the program output must be valid Org syntax in the given
context).  You can't have the same program produce tables, vectors and
LaTeX output just by switching the results type.

> But I think the main problem comes from the way that Babel expects the
> result. In Babel, and except for :results output, the last expression in
> perl is considered the input to the results.

That is with the default wrapper function, which expects the program to
return something that either is a string or interpolates to a string
that Babel can interpret.  You can easily define one yourself that does
different things, like simply open the output file then select the
filehandle for output.  That's what I'd do in any case and I think it
would work just as you want.

--8<---------------cut here---------------start------------->8---
(defvar org-babel-perl-wrapper-method
  "{
  my $prog = q(%s);
  open my $BO, qq(>%s) or die qq(Perl: Could not open output file.$\\);
  select $BO;
  eval( $prog );
}")
--8<---------------cut here---------------end--------------->8---

> This is implementing by
> saving the last expression into a variable, and printing each value
> separated by a "\n" (including the last). So basically, org takes the
> last expression, and outputs them to the babel input file one per line.

Yes, not the most elegant way, not perlish and all that; but there's
nothing to stop you from making that last expression a string variable
that has collected your output.  Try the above and let me know if that
addresses your concerns, if only partly.

As for debugging, the output files that Perl produces and Babel then
interprets are kept in the temporary folder, org-babel-eval-read-file
doesn't delete them after use (it probably should, though).


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Waldorf MIDI Implementation & additional documentation:
http://Synth.Stromeko.net/Downloads.html#WaldorfDocs




reply via email to

[Prev in Thread] Current Thread [Next in Thread]