[LA.pm] String handling like C array

Robin Rowe rower at movieeditor.com
Sat Feb 4 01:10:14 PST 2006


Peter,

> You're looking to learn regular expressions.

Actually, I should have said that I'm not. Regex can be very useful, but 
sometimes I'd rather not. My C example was only to illustrate the idiom. 
Didn't mean to mislead anyone to think I'm really swapping 'x' and 'y' 
in a string.

The Perl books tend to show only regex examples. Sometimes, I just want 
to walk the string. One reason is that I may be passing the string to a 
system call. The consequences of a bug in my use of regex can be too big 
a risk. And sometimes regex isn't powerful enough, that it can't 
implement branching algorithms.

> Typically, 10 lines of C string code is just 1 line of perl.

Possibly, but I don't write typical C code. ;-)

Funny story, I once had a discussion with a Scheme evangelist who said 
C++ is always more lines of code for the same problem. I said fine, try 
me. He named a homework problem from some Scheme course. I was able to 
implement (correctly) with fewer lines of C++ than he did in Scheme. 
However, the algorithm in my solution was completely different and 
required an understanding of combinatoric number theory. He said it was 
unfair, that nobody could be expected to understand my C++ code. I said 
I felt the same way about Scheme! ;-)

The motivation for me to use Perl is for portable glue code (to avoid 
bash/bat for pipeline scripts) and for web cgi where compiling is 
inconvenient.

> You can learn more about REs (for the novice or
> if you are having troubles reading or writing them) at:
> 
> http://peterbenjamin.com/seminars/regexp/regular.expressions.lesson2.1.html

Looks very helpful. Though not what I was looking for at the moment, 
good to know where I can find a good regex reference.

Thank you,

Robin




More information about the Losangeles-pm mailing list