On 2002.01.22 00:43 Peter Scott wrote:
> Seems that it can be extended to arbitrary operators without losing 
> any conciseness:
> 
> #!/usr/bin/perl -l
> for(@ARGV){push@s,$_ and next if/\d/;/^p/&&print$s[-1]and 
>next;eval"\$s[-2]$_=pop\@s"||die"!"}
> 
> $ ./foo 5 9 + p 3 % 5 / p 9 '**' p
> 14
> 0.4
> 0.000262144

I see two problems :

1. you can't write 1 1+p, whitespace are needed.

2. 1 1 - dies. You shouldn't eval or die, you should die if $@ is set.

BTW. about little languages. Anyone has implemented the ex(1) language, or
a decent subset of it, to operate on arrays of strings ?
You know, something like :

ex_commands( <<EX, @lines );
5,$d  "delete lines from the 5th to the end of the array
2y    "copy line #2
$put  "and put it at the end
EX

(hey, you could even wrap it in a Inline::Ex module!)

Reply via email to