<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
 --></style><title>the other magic e</title></head><body>
<div>Hi Joseph,<br>
</div>
<div>I really enjoyed your talks on the obscure corners of emacs and
perl.  I almost hate to confess my vimness.</div>
<div><br></div>
<div>As we discussed at the meet-up, I use the perl<b> e</b> modifier
in my wiki-converter hack ... here is a simple example of how it looks
in cado:</div>
<div><br>
----------------------------------------------------------------</div>
<div><b>cado -q</b><br>
data := << (<br>
1 fred<br>
2 sam<br>
3 sally</div>
<div>)</div>
<div><br>
CG_SUBSTITUTE_SPEC := s/^(\d+)\s+/append_op("$1+",
"FOO")/emg<br>
output = $data:substitute<br>
<br>
%echo output=$output<br>
%echo FOO=$FOO</div>
<div><b>^D</b><br>
output=1+fred<br>
2+sam<br>
3+sally<br>
<br>
FOO=1+2+3+<br>
----------------------------------------------------------------<br>
<br>
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.</div>
<div><br></div>
<div>Also note that<b> :=</b> in cado is the literal assignment
operator, which avoids interpolation of the right hand side of the
assignment (use plain<b> =</b> for that).  Stole that from gnu
make.</div>
<div><br></div>
<div>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.</div>
<div><br></div>
<div>I believe this will also work with perl grep(), implemented in
cado as ":g".  Gee, I should try that.  :)</div>
<div><br>
Yet another fun way to play with perl RE's.<br>
<br>
cheers,</div>
<div>-Russ<br>
</div>
<div>P.S.  I pushed out the latest version (1.97) of the
interpreter this weekend:</div>
<div>http://sourceforge.net/projects/cado/files/</div>
</body>
</html>