From mboxrd@z Thu Jan 1 00:00:00 1970 From: asr@ufl.edu (Allen S. Rout) Subject: PERL, org-mode and literal document input. Date: Mon, 02 May 2011 16:25:03 -0400 Message-ID: <87ei4gc0kg.fsf@ufl.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from eggs.gnu.org ([140.186.70.92]:38654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QGzm1-0007Hi-3j for emacs-orgmode@gnu.org; Mon, 02 May 2011 16:31:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QGzlz-00074c-I4 for emacs-orgmode@gnu.org; Mon, 02 May 2011 16:31:17 -0400 Received: from lo.gmane.org ([80.91.229.12]:53878) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QGzlz-00074Q-6u for emacs-orgmode@gnu.org; Mon, 02 May 2011 16:31:15 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QGzly-0003ZZ-2J for emacs-orgmode@gnu.org; Mon, 02 May 2011 22:31:14 +0200 Received: from n128-227-126-167.xlate.ufl.edu ([128.227.126.167]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 02 May 2011 22:31:14 +0200 Received: from asr by n128-227-126-167.xlate.ufl.edu with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 02 May 2011 22:31:14 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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