Why use Perl when we've got Python?!

John Stevens jstevens at bamboo.verinet.com
Sat Aug 14 10:57:21 EDT 1999


On 14 Aug 1999 03:36:23 GMT, Sam Holden <sholden at pgrad.cs.usyd.edu.au> wrote:
>On Sat, 14 Aug 1999 03:08:33 GMT,
>    John Stevens <jstevens at bamboo.verinet.com> wrote:
>>On 14 Aug 1999 02:32:12 GMT, Sam Holden <sholden at pgrad.cs.usyd.edu.au> wrote:
>>>On 13 Aug 1999 20:04:03 -0700,
>    John W. Stevens <jstevens at basho.fc.hp.com> wrote:
>>>>
>>>>Perl doesn't have lists.  Python doesn't have built-in arrays.
>>>
>>>You should learn some perl you now..
>>>
>>>@array = (1,10,20,30);
>>>$from_list = (1,10,20,30);
>>>$from_array = @array;
>>>print "$from_list\n$from_array\n";
>>>
>>>Will output :
>>>30
>>>4
>>
>>The @ prefix denotes an array.  You, yourself, should learn
>>Perl.  Calling an array a list, doesn't make it one.
>
>Can you read?
>
>Can you see a @ in the following line of code :
>
>$from_list = (1,10,20,30);

Your example included:

@array = (1,10,20,30);
$from_list = (1,10,20,30);
$from_array = @array;
print "$from_list\n$from_array\n";

The line you specify does not contain a list, it contains a
tuple.

>No you can't.  Is there an array in that line of code?

No, and that isn't a list, even if you call it one.  It is a tuple.

>No. Is there a list
>in that line of code?

No, it's a tuple, not a list.

>Yes.

No.  Calling it a list, doesn't make it a list.

To be able to perform operations on the above, you'd have to
assign the values of the tuple to an array.

In which case you'd be performing array operations, not list
operations.

>>Not built in, it doesn't, unless you define array and list as being
>>different words for exactly the same type/class.
>
>I don't think you can get more built in then perl lists.

You get tuples in Perl.  The book calls then lists, but you cannot
perform any of the standard, defined list operations on a Perl
"list".

All "list" operations are performed by shoving "lists" into
array's.

Go ahead, show me a variable that contains a list.  In your
example:

$from_list = (1,10,20,30);

$from_list isn't a list.

>Again I repeat, here is a perl list : ('a', 'b', 'c') or qw(a b c)

Again, you are wrong.  The construct ('a', 'b', 'c') is a tuple.
Perl'ers may call it a list, but how do you perform a an insert
on the above?

You don't.  You copy the contents of your tuple into an array,
then perform array operations on that array.

>>I know Perl.  You need to learn Python.
>
>Did I mention a single bit of python syntax in my post? No. 

So what?  I can still make a comment.  And if you had been
paying attention, you would have realized the context of this
thread.

>What was the point of saying I need to learn Python?

Because, in the words of TC, "Learning is a good thing".

More specifically, had you studied Python, it would have been
clear that what Perl calls a list is more properly refered to
as a tuple.

>You might as well have told me to learn C or Lisp.

Yes.  You should.  Had you learned Lisp, list processing would
be second nature to you, and you would have a clearer idea between
"lists" and "tuples" and "arrays".

>>If @ denotes list, then the following Perl would be illegal:
>>
>>@ary = (1, 2, 3);
>>@ary[5] = "Test";
>>
>>But, obviously, this is not illegal.
>
>@ary[5] is an array slice.

Yes.  So what?

>It is an array. It happens to be an array 
>that constists of only one element.

Again, so what?

>Why would it be illegal?

If @ary were a list, it would be illegal.

>It is just
>the special case of :

Stop.  You are talking about arrays, not lists.  I repeat, if
@ary were a list, the above operation would be illegal.

>@ary[1,2,3,4,5,10,20]
>
>It is an array. Thus it has a @.

Yes.  It is an array, not a list.  Though to be perfectly anal,
it might be best to refer to that as a vector. . . ;->

>>Really?  What is the prefix character that denotes a list?
>
>You can't have a list in a variable.

Correct.  So, Perl does not have lists, it has tuples.

>Again here is a list :
>
>(1,2,3,4,5,6,7,8)

No, that is a tuple.

>push( (1,2,3,4,5), 6); 
>
>This results in an error message, funnily enough the message is :
>Type of arg 1 to push must be an array (not list)

Yes.  But calling a tuple a list (or for that matter, calling an
array a list) does not make it one.

Had that been a real list, and assuming that "push" really means,
append, that should have been legal.

>Still claim perl has no lists?

Yes.

>Of course you know better then perl itself.

In this case, I would say that Perl should use the same terminology
as other fields of study.  So, yes, I would consider that Perl
makes a mistake, calling this a list.

John S.




More information about the Python-list mailing list