From: asr@ufl.edu (Allen S. Rout)
To: emacs-orgmode@gnu.org
Subject: PERL, org-mode and literal document input.
Date: Mon, 02 May 2011 16:25:03 -0400 [thread overview]
Message-ID: <87ei4gc0kg.fsf@ufl.edu> (raw)
Greetings.
I've got a YAML config file and some processing I'm doing to it. I'd
love to have both the bits inside the maintenance document I'm writing
to manage a service. This seems a perfect use for code blocks and their
evaluation. However, I get behavior out of my attempt to do this which
I find strange.
I include a minimal, failing example below.
The problem "appears" to be somewhere in the :var reference designed to
introduce the other code block. There are two problems, one pretty
egregious, the other somewhat subtle.
Egregious first:
For some reason, whatever process sucks up config_yml and inserts it
into '$config' in mogrify_pl just elides the first two lines.
Additionally, the contents of the variable are very strangely
formatted. The contents of most of the first YAML document (less the
first two lines) are each on a separate line.
However, the last of the first doc and all of the second doc are in a
single line.
Subtle:
The last few newlines are also elided. This might not seem to be a big
deal, but YAML really wants to end with a trailing newline. I figure I
should be able to express that in the doc, and not tag one on in my
code.
...
If I add a #+begin_src line to config_yml, and then build a results
section by hand, and copy the identical document there, then the
variable is imported more or less as I'd expect: $config is one large
scalar value, with the contents of config_yml inserted. The trailing
newlines are still stripped, but this is better at least.
I've been searching for something like "Echo this" to put in my
begin_src; it would seem a little silly but not awful to define a
process to just copy the contents of the source block to the result, and
go from there. But it's inelegant, to say the least.
...
So: Is there a conventional way I should get org to treat the source
block 'the same way' it treats the results block? Failing that, is
there a common idiom to run a source block to get the result "Echo me
verbatim into the results block" ?
I see profligate use of org-babel-trim in the code. Does that mean that
permitting leading or trailing whitespace is a regular source of
problems? I didn't want to start dinking with it casually.
...
Any pointers would be deeply appreciated.
*** YAML transform.
#+srcname: config_yml
---
erpalpha:
- alpha-rac-1.erp.ufl.edu
- alpha-rac-2.erp.ufl.edu
erpbeta:
- beta-rac-1.erp.ufl.edu
- beta-rac-2.erp.ufl.edu
---
erpalpha:
FS: /export/alpha
nodes:
erpalpha: ''
erpbeta: RO
erpbeta:
FS: /export/beta
nodes:
erpalpha: RO
erpbeta:
#+end_src
#+srcname: mogrify_pl
#+begin_src perl :results output :var config=config_yml()
use YAML();
use Data::Dumper;
# $stream = join("",<$foo>);
print "===$config===\n";
print $#config,"\n";
foreach $line (@{$config})
{ print "[$line]\n"; }
print Dumper($config);
# ($nodegroups,$filespaces) = YAML::Load($config);
# print YAML::Dump($nodegroups,$filespaces);
#+end_src
#+results: mogrify_pl
#+begin_example
===ARRAY(0x853b818)===
-1
[alpha-rac-1.erp.ufl.edu]
[alpha-rac-2.erp.ufl.edu
erpbeta:]
[beta-rac-1.erp.ufl.edu]
[beta-rac-2.erp.ufl.edu
---
erpalpha:
FS: /export/alpha
nodes:
erpalpha: ''
erpbeta: RO
erpbeta:
FS: /export/beta
nodes:
erpalpha: RO
erpbeta:]
$VAR1 = [
'alpha-rac-1.erp.ufl.edu',
'alpha-rac-2.erp.ufl.edu
erpbeta:',
'beta-rac-1.erp.ufl.edu',
'beta-rac-2.erp.ufl.edu
---
erpalpha:
FS: /export/alpha
nodes:
erpalpha: \'\'
erpbeta: RO
erpbeta:
FS: /export/beta
nodes:
erpalpha: RO
erpbeta:'
];
#+end_example
- Allen S. Rout
next reply other threads:[~2011-05-02 20:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-02 20:25 Allen S. Rout [this message]
2011-05-05 17:19 ` PERL, org-mode and literal document input Eric Schulte
2011-05-06 20:21 ` Allen S. Rout
2011-05-06 20:55 ` Eric Schulte
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ei4gc0kg.fsf@ufl.edu \
--to=asr@ufl.edu \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).