[sf-perl] the other magic e

Russ Tremain russt at releasetools.org
Mon Apr 2 11:40:32 PDT 2012


Hi Joseph,

I really enjoyed your talks on the obscure corners of emacs and perl. 
I almost hate to confess my vimness.

As we discussed at the meet-up, I use the perl e modifier in my 
wiki-converter hack ... here is a simple example of how it looks in 
cado:

----------------------------------------------------------------
cado -q
data := << (
1 fred
2 sam
3 sally
)

CG_SUBSTITUTE_SPEC := s/^(\d+)\s+/append_op("$1+", "FOO")/emg
output = $data:substitute

%echo output=$output
%echo FOO=$FOO
^D
output=1+fred
2+sam
3+sally

FOO=1+2+3+
----------------------------------------------------------------

Two things to note:  1) the contents of $output has the result of 
each call to append_op(), which returns the value of the append.  2) 
the creation of a new cado variable $FOO, with the integer from each 
line of data isolated.

Also note that := in cado is the literal assignment operator, which 
avoids interpolation of the right hand side of the assignment (use 
plain = for that).  Stole that from gnu make.

Granted, you have to know how to call a cado op  (in this case 
:append), but given that, you have full access to all the cado 
functions from within a perl substitution, granted by the magic e.

I believe this will also work with perl grep(), implemented in cado 
as ":g".  Gee, I should try that.  :)

Yet another fun way to play with perl RE's.

cheers,
-Russ

P.S.  I pushed out the latest version (1.97) of the interpreter this weekend:
http://sourceforge.net/projects/cado/files/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20120402/bc244eea/attachment.html>


More information about the SanFrancisco-pm mailing list