Ron Johnson <ron.l.johnson@cox.net> writes:
> On Sat, 2003-07-12 at 03:57, Mark A. Hershberger wrote:
>
>> Some things are virtually impossible w/o regular expressions.
>
> Possible in Python, but takes an aggravating amount of 3GL coding.
Yes, and Python seems to want to objectify everything. Which, while
sometimes really helpful, is sometimes really annoying.
>> Perl:
>>
>> for(<*>) {if(/ +/) {$o=$_;s/ +/_/g;rename $o,$_}}
One think I like about Perl is the Syntactic Sugar. This leads to
the accusation that TMTOWTDI is the real problem with Perl, but,
frankly, that's a tired argument by languages with less power. Learn
the language. Learn the idioms. Don't be afraid to learn more.
rename @{map {($n = $_) =~ tr/ /_/; [$_, $n]}}
if / /
for(<*>);
We don't expect a Lisp newbie to understand closures and lambdas after
getting past the syntax of parenthesis, so why do we expect a Perl
newbie to be able to grok everything we show him?
Sure, we can write it in such a way that anyone can understand it, but
why? One measure of how quickly a programmer can use a language bring
his ideas to fruition is lines of code. Perl obviously wins there.
It further wins by the easy access to power that is CPAN.
> 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.
s,assumptions,variables,g
So, try it with no implicit variables:
for $file (<*>) {
if($file =~ m{ }) {
$new = $file;
$new =~ tr/ /_/;
rename $file, $new;
}
}
Do you find pronouns in English a hard concept to grasp? They are
part of the implicit assumptions of the language. Instead of using
George's name every time we want to talk about him, we just use "him"
or "his". This is similar to the concept of $_ and _ in Perl.
The thing to remember about Perl is that it isn't an ivory tower
language. It is a mucky, dirty language because, like natural
languages, it evolves, it gathers stuff and looses other things.
Perl assumes you are reasonably intelligent.
This does make it a little harder to pick up, just as any foreign
language is difficult for most adults. And, if you aren't a native
speaker, you won't understand all the idioms right away. But, if you
are willing to stick it out and keep an open mind, you'll find more
power than you thought possible.
But, let me be clear. Languages like Lisp, Perl, and Smalltalk are
much maligned languages because they are "different". People who grew
up reading C or C++ or Java or C# look at Lisp or Perl and shake their
heads because they are so dramatically different. Perl must be
approached using the Beginners Mind.
> Is there any documentation for the functions in CPAN similar to
> those of the standard Python library?
What is in the standard Python library? I imagine that the standard
distribution for Perl covers about the same ground as Python, though
I'm sure there are differences.
That said, everything in core Perl is also on CPAN. Tons of
documentation hyperlinked and mirrored accross the globe:
<http://search.cpan.org/dist/perl/>.
Mark.
___________________
Nolug mailing list
nolug@nolug.org
Received on 07/12/03
This archive was generated by hypermail 2.2.0 : 12/19/08 EST