PyPerl Developer's Guide |
||
Table of Contents
1. Why PyPerl?I've used perl for several years, and been very impressed with its ease of use. When you need to do something new, chances are there is an idiom which lets you do it in a few keystrokes. I didn't want to lose that in moving to python. Somehow I wanted to get the benefits of perl's idioms with the robust scalability and maintainability of python. So the idea is to emulate perl idioms, no matter how we implement the python code under the covers. See tests (test/basic_tests.py) for those idioms in use.
2. ApproachWe make a PyPerl object, so we can protect the "globals" from conflicts if we happen to want several copies running in parallel. Then we establish the foundations:
We need to expand "$" and "@" names in strings. This in turn requires access to the caller's symbol table. "_expand" handles this. Not a perfect rendition, but good enough for the idiom. This is so useful, we export it as the "__call__" function of PyPerl. File operators (e.g., "-e") turn into functions of the same name. All the functions which take strings (including file operators) need to call the expansion process. Regular expression functions like "m" need to be rendered as python re actions. I may not have all the variants covered, but enough to take a run at it. In particular, an idiom I was missing in python can now be handled:
if p.m("he(l+)o","helllo, world"): print p("found $1") After that, it is mostly just going through Programming Perl, implementing functionality as we go.
|
||
Creator: Harry George Updated/Created: 2001-12-28 |