Re: 20050111: list basics

From: Abigail (abigail_at_abigail.nl)
Date: 01/12/05

  • Next message: Denis S. Otkidach: "Re: os.spawnv & stdin trouble"
    Date: 12 Jan 2005 08:22:04 GMT
    
    

    Xah Lee (xah@xahlee.org) wrote on MMMMCLII September MCMXCIII in
    <URL:news:1105512773.543336.29930@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 bull***. 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,@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
    bull***.

    Abigail

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

  • Next message: Denis S. Otkidach: "Re: os.spawnv & stdin trouble"