20050111: list basics

Abigail abigail at abigail.nl
Wed Jan 12 09:22:04 CET 2005


Xah Lee (xah at xahlee.org) wrote on MMMMCLII September MCMXCIII in
<URL:news:1105512773.543336.29930 at c13g2000cwb.googlegroups.com>:
::  
::  # in perl, list is done with paren ().

Wrong. Except in a few cases, parens don't make lists. Parens are
used from precedence. *Context* makes lists.

::  # the at sign in front of variable is necessary.

The at sign in front of a variable means the variable is an array.
Arrays are *NOT* lists.

::  # it tells perl that it is a list.
::  @a = (0,1,2,'three',4,5,6,7,8,9);
::  
::  # perl can't print lists. To show a list content,
::  # load the package Data::Dumper, e.g.
::  use Data::Dumper;
::  print '@a is:', Dumper(\@a);

Utter bullshit. Perl's print statement has no problem accepting a
list. In fact, YOUR EXAMPLE PASSES A LIST to print. But this works
fine too:

    @a = ('Xah ', 'Lee ', 'does ', 'not ', 'know ', 'Perl');
    print @a;
    __END__
    Xah Lee does not know Perl

::  # the backslash in front of @a is to tell Perl
::  # that "get the "address" of the "array" @a".

Wrong. Perl is not C. You get a reference, not a pointer.

::  # it is necessary in Dumper because Dumper is
::  # a function that takes a memory address.

Wrong. Perl functions don't take memory addresses. Perl doesn't allow
the programmer to do direct memory access.

::  # see perldoc -t Data::Dumper for the intricacies
::  # of the module.

Please do so yourself.

::  # to join two lists, just enclose them with ()
::  @b = (3,4);
::  @c = (@a, at b);
::  print '\@c is', Dumper \@c;
::  # note: this does not create nested list.

There is no such thing as "nested lists". 

::  # to extrat list element, append with [index]
::  # the index can be multiple for multiple elements
::  @b = @a[3,1,5];
::  print Dumper \@b;

Why are you printing to the Dumper filehandle?

::  # to replace parts, do
::  $a[3]= 333;
::  print ' is', Dumper \@a;
::  # note the dollar sign.
::  # this tells Perl that this data is a scalar
::  # as opposed to a multiple.
::  # in perl, variable of scalars such as numbers and strings
::  # starts with a dollar sign, while arrays (lists) starts with

Again, arrays are NOT lists.

::  # a at @ sign. (and harshes/dictionaries starts with %)
::  # all perl variables must start with one of $,@,%.

Or *, or &. And some variables don't have a sigil in front of them.

::  # one creates nested list  by
::  # embedding the memory address into the parent list
::  @a=(1,2,3);
::  @b = (4,5, \@a, 7);
::  print 'nested list is', Dumper \@b;

Rubbish. That's not a nested list. @b is an *ARRAY*, whose third element
is a *REFERENCE* to another *ARRAY*.

::  # to extrat element from nested list,
::  $c = $b[2]->[1];
::  print '$b[2]=>[1] is', $c;
::  
::  # the syntax of nested lists in perl is quite arty, see
::  # perldoc -t perldata
::  Xah


Please Xah, do the Perl and Python communities a favour, and stop posting
bullshit.


Abigail
-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'



More information about the Python-list mailing list