[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] How to pass a block of text to a code block as data?
From: |
Sean O'Halpin |
Subject: |
Re: [O] How to pass a block of text to a code block as data? |
Date: |
Sat, 9 Feb 2013 18:49:26 +0000 |
On Sat, Feb 9, 2013 at 2:59 AM, Michael Baum <address@hidden> wrote:
>
> - What signals the end of the block of text to be used as data? I take it
> that it's important that these all be comment lines staring with a colon
> after the #+name label? Is there a way to do the same thing with a begin and
> end block construction?
>
> - In this line:
>
> #+begin_src sh :stdin lines-of-text :results output
>
> does the flag :stdin mean that the following named block literally becomes
> the STDIN stream for the code block? If I replace your shell/grep example
> with this:
>
> #+begin_src perl :stdin lines-of-text :results output
> while (<>) {
> print $_;
> }
> #+end_src
>
> ...it doesn't work, although as far as I know that perl code snippet should
> in fact simply print out the incoming lines from stdin.
>
> Thanks again,
>
> Michael
Hi,
The :stdin option is only defined for shell and awk AFAIK. (Might be
an idea to add to other languages..)
You can pass in a variable referring to the block of text, as shown
below (example for ruby but should work for perl):
#+begin_src org
#+name: more-lines-of-text
#+begin_example
What signals the end of the block of text to be used as data? I take
it that it's important that these all be comment lines staring with a
colon after the #+name label? Is there a way to do the same thing with
a begin and end block construction?
#+end_example
#+begin_src ruby :var lines=more-lines-of-text :results output
puts lines.reverse
#+end_src
#+RESULTS:
: ?noitcurtsnoc kcolb dne dna nigeb a
: htiw gniht emas eht od ot yaw a ereht sI ?lebal eman+# eht retfa noloc
: a htiw gnirats senil tnemmoc eb lla eseht taht tnatropmi s'ti taht ti
: ekat I ?atad sa desu eb ot txet fo kcolb eht fo dne eht slangis tahW
#+end_src
Regards,
Sean