Re: array question (newbie)



"Jerry Cloe" <tom@xxxxxxxxxxxxxxxxxxx> wrote in
news:ZM9Re.19164$mb4.2853@xxxxxxxxxxxxxxxxxxxxx:

> Having an array:
>
> @mylist=("apples", "oranges", "bananas");

Easier to type:

my @mylist = qw(apples oranges bananas);


> And refering to a particular element, which syntax is correct? (or
> are both correct)?
>
> print "Item 2 is $mylist[1]\n";

This is correct.

> or
> print "Item 2 is @mylist[1]\n";

That is an array slice, probably not what you intended.

> Both seem to work,

You don't have warnings enabled. Have you read the posting guidelines
for this group yet?

Sinan

--
A. Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
.



Relevant Pages

  • Re: foreach in my
    ... > I assume because it's inside the my $req section. ... $req->is a reference to an array ... Please do read the posting guidelines for this group for information on ... Sinan Unur ...
    (comp.lang.perl.misc)
  • Re: random numbers
    ... > These numbers must match to the number of an array. ... is better because it allows you to turn warnings for selected lexical ... Please do read the posting guidelines for this group tolearn how you can ... Sinan Unur ...
    (comp.lang.perl.misc)
  • Re: .join() !== + a + b; // for some a and b
    ... The one seemed obvious until your more detailed explanation below, ... that made it necessary to look deeper into the syntax. ... one an Array object reference and one ... seems wrong with the expression evaluation on the left side of the logical ...
    (comp.lang.javascript)
  • Re: How to do "Compile time" initialization of record array?
    ... It should be noted that there is proposed syntax for C# 3.0 which will ... public struct MyStruct ... What actually gets compiled is the same array initialization as there is ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: It Hurts When I Do This
    ... We do have a syntax that means the entire array - the array name. ... I disagree that it helps to use a special notation to indicate that ... I think it a mistake to throw all this kind of thing in the language. ...
    (comp.lang.fortran)