Why use Perl when we've got Python?!

Sam Holden sholden at pgrad.cs.usyd.edu.au
Sat Aug 14 06:08:05 CEST 1999


On Sat, 14 Aug 1999 03:18:19 GMT,
    John Stevens <jstevens at bamboo.verinet.com> wrote:
>On 14 Aug 1999 02:39:10 GMT, Sam Holden <sholden at pgrad.cs.usyd.edu.au> wrote:
>>On 13 Aug 1999 20:05:12 -0700,
>>	John W. Stevens <jstevens at basho.fc.hp.com> wrote:
>><snip>
>>>
>>>Thanks for the two missing magic characters (@$, and =>).  I always
>>>have to look them up.
>>
>>Learn some perl then. @ is pretty fundamental. $ is pretty fundamental.
>>What happens when you tell a scalr to be an array is pretty fundamental.
>
>Oh, I *KNOW* the semantic.  I just can't remember the syntax.
>
>As for calling the conversion of a scalar to an array "pretty
>fundamental". . . can you say "Extreme Exageration"?
>
>Tom tells me that Perl doesn't exclude non-computer scientists,
>then you guys start throwing around references to references. . .

That could simply have been a reference. Or a symbolic reference.

What is fundamental is that a @ tacked on the front indicates that it is an
array. So given @$fred, even with no knowledge of what that exactly means
you should be able to tell that it is somehow treating $fred as an array.

>
>:-)
>
>>Only if you don't know perl.
>
>No, it is confusing to the average programmer.  If it isn't
>confusing, to you, then you've spent a *LOT* of time learning
>and using Perl.
>
>>$dict is a scalar. %dict is a hash. In that
>>example a scalar was used. 
>
>Yes. . . is it a hash, or a scalar?  If it is a scalar, why
>is it called dict?  If it is a hash, then why is it prefixed
>by $?  If this is a reference instead of a scalar, then why
>doesn't it have it's own special prefix character.  ;->

It's a scalar. It is named dict because TomC called it that. It is
also named that since it is a reference to a hash. I use code like this
in C quite a bit :

Tree *tree;

Even though tree isn't a tree, but a pointer to a tree. If you don't like
that then don't use it. It's a fairly common thing to do though, I've seen
it used in pascal, C and C++, so it is not unique to perl.

>
>>At least in the discussions I have with people about python I don't
>>complain about python syntax I don't understand I just ask what it means.
>
>I am not complaining about syntax I don't understand.  I am complaining
>about syntax that is unecesarily difficult to learn, remember, and use.
>
>>Instead of calling it confusing people who actually want to learn something
>>ask what it means, and why it is so. You obviously don't want to
>>learn but only to criticise. That's fine but it would be better to just
>>post to the python group...
>
>What, you believe that you are a mind reader?
>
>You are wrong.  I know what the syntax means.  I criticize because
>it is indeed confusing, and difficult to remember.

If you know what it means then why do you continually get it wrong
throughout this thread?

>
>>You can write Perl programs that resemble sed, or awk, or C, or Lisp, or
>>Python. This is Officially Okay in Perl culture.
>
>You cannot write Perl that resemble Python.  You are required to 
>use curly braces as block delimiters.

In fact you are not. You are wrong yet again. Actually thinking about how
perl works for a minute would show you that perl is in fact flexible. 
it is not a lie when people say perl doesn't force you to write a 
particular way.

Here is some code from Damian Conway from the 'Impythonating PERL' thread
in march.

package impythonate;
use Text::Tabs;
my ($active, @bracket) = (0, ('{', ';', '}') );
sub import
{
  return 1 if ($active++);
  open CODE, $0 or die "couldn't translate $0";
  my ($code, $transcode, $lastindent) = (join('',<CODE>), '');
  $code =~ s/\\\n/ /g;
  foreach (split /\n/, $code)
  {
  my ($indent,$notempty) = /\A([ \t]*)(\S?)/;
  $indent = length(expand($indent));
  $transcode .= $bracket[1+($lastindent<=>$indent)]
    if $notempty && defined $lastindent;
  $transcode .= "$_\n";
  $lastindent = $indent if $notempty;
  }
  eval $transcode and exit or die $@;
}
1;
 
And here is his sample code that is now valid perl (although anyone who uses
it for real code should be killed) :
 
#Now newlines replace colons and indentation replaces brackets:
 
use impythonate; # STILL NEED THAT ONE SEMICOLON, DAMMIT!
 
for $i (1..10)  # COMMENTS ARE OKAY
  print "$i: "
  my $isq =  \
  $i **2 # LINE CONTINUATIONS WORK AS IN PYTHON
  print " $isq\n"
 
print "done\n"

-- 
Sam

Basically, avoid comments. If your code needs a comment to be
understood, it would be better to rewrite it so it's easier to
understand.	--Rob Pike




More information about the Python-list mailing list