How to connect input to src_block as stdin?

Consider the following perl fragment in org-babel that uses <STDIN>.

** Ans 2
   #+begin_src perl :results output
     use Math::Trig;
     $rad = <STDIN>;
     $circumference = 2*pi*$rad;
     print "Circumference of circle is $circumference";
   #+end_src

Can I connect the input to this block from another block?

Say:

#+begin_src text :name test-input
  12.5
#+end_src
+5
source share
1 answer

You can pass $raddirectly to the perl script from the block #+results: see passing arguments to code blocks in a manual.

It will give

#+begin_src perl :results output :var rad=test-input

Use as input

#+results: test-input
:  12.5
+3
source

All Articles