On Sat, 2003-07-12 at 03:57, Mark A. Hershberger wrote:
> Ron Johnson <ron.l.johnson@cox.net> writes:
>
> > I'm slightly above newbie regarding REs, and, IMHO, they *are*
> > line noise. Powerful line noise.
>
> Some things are virtually impossible w/o regular expressions.
> Perl-style REs have been incorporated into many languages and tools
> (by virtue of the pcre library). PHP, Python, Exim and others are
> all beneficiaries.
Possible in Python, but takes an aggravating amount of 3GL coding.
> Consider Regular Expressions a mini-language that you can learn once
> and use in lots of different places. There's the idiosyncrasies that
> come with different dialects (sed's REs are different in annoying
> ways), but if you've got the language the dialects aren't that
> difficult.
>
> > I've tried learning Perl, but the pain threshold is so much lower
> > for Python. Writing something to, for example, go thru a directory
> > converting all spaces in filenames is much shorter in Perl than
> > in Python, but a Python newbie who knows how to program (but has
> > not joined The Unix Cult) would understand the code, whereas s/he
> > would be baffled by the Perl code.
>
> Perl:
>
> for(<*>) {if(/ +/) {$o=$_;s/ +/_/g;rename $o,$_}}
Let's make that a non-1-liner:
for(<*>)
{
if(/ +/)
{
$o=$_;
s/ +/_/g;
rename $o,$_
}
}
The implicit assumptions in every line except the braces lines makes
this hard to read unless you grok REs and know Perl's implicit
assumptions.
> Python:
>
> for file in os.listdir("."):
>
> if file.find(" ") != -1:
>
> rename file, re.sub(" ", ".", file)
Tweaked to do recursive filename changing:
import os, re, os.path
def each_dir(arg, dirname, names):
for file in names:
file1 = os.path.join(dirname, file)
if os.path.isfile(file1) and (file.find(' ') != -1):
os.rename(file1, os.path.join(dirname, re.sub(' ', '_', file)))
os.path.walk('.', each_dir, '')
> By the way, I don't know Python, I just pick up new languages. Lisp
> is the hardest one I've had to pick up, but also, in some ways, the
> most powerful.
> In other ways, Perl is the most powerful. CPAN is an amazing resource
> an no other language comes close to that kind of utility.
Is there any documentation for the functions in CPAN similar to
those of the standard Python library?
-- +-----------------------------------------------------------+ | Ron Johnson, Jr. Home: ron.l.johnson@cox.net | | Jefferson, LA USA http://members.cox.net/ron.l.johnson | | | | 4 degrees from Vladimir Putin +-----------------------------------------------------------+ ___________________ Nolug mailing list nolug@nolug.orgReceived on 07/12/03
This archive was generated by hypermail 2.2.0 : 12/19/08 EST