[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Newbie list question



bsfa@knoware.nl (Bert Altenburg) wrote:
>Chris Nandor wrote:
>>>Simple as it is, I can't see why this doesn't compile.
>>>
>>>@myList = ('a','b','c');
>>>$x = @myList(1);
>>>print "$x";
>
>>Now, for your broken array access syntax.  All books describe the proper
>>way to do this.
>
>Quote from: Perl for Dummies. second edition page 100.  
>**
>Specifying slices of lists 
>
>What happens if you want to address just one element of the list, and not 
>the list in its entirety? Because lists are ordered, you can refer to 
>each element by its numbered place in the list.  You can say to Perl  
>"Set the variable $Dub to the value of the third element of the list 
>@music." For example, 
>
>$Dub = @Music(2);
>**

That is so totally inconceivable that this would be in a popular* Perl book. 
Anyone who's done more than two days' worth of Perl programming knows that's
not even close to how Perl works.  The heading says the section is about
slices, then it talks about accessing individual array elements (NOT slices),
and then it gets the syntax so gloriously wrong.  If that's truly what the book
says, then it's hard to believe the book went through any editor who knew how
to write any Perl.


* It's popular, but I haven't read it so I don't know whether it's good.  If
you want to learn Perl, try the books that others would recommend, like the
ones from O'Reilly, or MPPE, etc.


>(Below that slices are discussed). Apparently 100% of the books on Perl I 
>currently have describe the improper way as well.

Do you only have one book, which only talks about arrays once?  How about the
documentation that comes with Perl itself (you have that, I assume)?  The
following is from the top of the "perldata" manual page:

  Scalar values are always named with '$', even when referring to a scalar
  that is part of an array.  It works like the English word "the".  Thus
  we have:

    $days               # the simple scalar value "days"
    $days[28]           # the 29th element of array @days
    $days{'Feb'}        # the 'Feb' value from hash %days



>If a list of 'bugs' for the book is available somewhere, I'm looking 
>forward to hear about it and I promise to check it first before bothering 
>the @list.

I didn't see one on its web page at http://www.dummies.com/ .




# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org