ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: scanf style parsing
by Ralph Corderoy other posts by this author
Sep 29 2001 11:09AM messages near this date
Re: scanf style parsing | Re: scanf style parsing
Hi Tim,

>  > For Perl hackers it is easy to figure out regexp, but for us old
>  > C/C++ types, it's *tough*
>  
>  It's not usually easy to learn regexps, no matter what your
>  background.  I come from C/C++ roots (Turbo C++ 3.0) and TRS-80 BASIC
>  before that, and I certainly had no idea what regex's were really for
>  until I looked at Perl.
>  
>  I struggled with regex's for months. I even had to take some time
>  away from Perl and regex's to calm down and not be so intimidated.
>  Many Pythonistas I've heard in this ng had a lot of difficulty with
>  regular expressions, and with *good reason*.

An easy, sure fire way for any programmer to learn regex concepts is to
read Kernighan and Plauger's _Software Tools_ where, amongst many other
interesting topics, they implement a regex pattern matcher and preceed
to use it in their versions of grep, ed, etc.

This gives you an immediate understanding of how conceptually simple
the implementation is and also makes issues like greediness, or
pathological patterns, simple to understand.  

>  Regex's are useful and powerful.  But they're also very easy to
>  abuse.  I've actually seen the following Perl code:
>  
>      if ($filename =~ /\.txt$/) { ... }
>  
>  ...
> 
>  or, much more preferably:
>  
>      if filename[-4:] == '.txt':

Overall, the Perl code's better.  It didn't have to hard-code the
length of the string.

Cheers,


Ralph.

PS.  Every programmer should read _Software Tools_ anyway.

-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Bruce Dawson
Skip Montanaro
George Demmy
Hans-Peter Jansen
Quinn Dunkan
Tim Hammerquist
Ralph Corderoy
Toby Dickenson
Duncan Booth
Aahz Maruch
Aahz Maruch
Aahz Maruch
Stefan Schwarzer
Grant Edwards
Fredrik Lundh

Malcolm Tredinnick
Ralph Corderoy
Tim Hammerquist
Stefan Schwarzer
Greg Ewing
Skip Montanaro
Boyd Roberts
Steve Clift
Bruce Dawson
Tim Hammerquist
Tim Hammerquist
Tim Hammerquist
Skip Montanaro
Andrew Dalke
Fredrik Lundh
Oleg Broytmann
Andrei Kulakov
Duncan Booth
Chris Barker
Tim Hammerquist
Skip Montanaro
Jon Nicoll
Oleg Broytmann
Bruce Dawson
Skip Montanaro
Andrei Kulakov
Richard Jones
Skip Montanaro
Andrew Dalke

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved