Re: array question (newbie)



Hello Jerry,
:
Having an array:

@mylist=("apples", "oranges", "bananas");

And refering to a particular element, which syntax is correct? (or are both correct)?

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

Both seem to work, and looking at other code, I see it done both ways.

The first is a scalar value, the second is an array slice.

This is a frequently asked question. So you can use the "-q" option of the perldoc command to dig it up:

Run:

    perldoc -q array

and look for the section:

    "What is the difference between $array[1] and @array[1]?"



Regards,

Simon Taylor
--
www.perlmeme.org
.



Relevant Pages

  • Re: _genxtab doesnt work in compiled EXE file in Foxpro for Dos 2.6
    ... project and refering it directly by its file name. ... doing this all in foxpro for dos 2.6 on windows 2000. ... missing something in syntax. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Secure Scripts
    ... You'd think a search on encoding vbscript would have ... Jerry ... > Microsoft Script Encoder ...
    (microsoft.public.windows.server.scripting)
  • RE: how do i average the 2 smallest number in a range of six numbe
    ... You are missing a few parentheses, but Frank and Jerry both provided more ... concise formulas anyway. ... "zetatstrat" wrote: ... >> Is there problem with syntax, or perhaps another to accomplish what I am ...
    (microsoft.public.excel.misc)
  • array question (newbie)
    ... Having an array: ... And refering to a particular element, which syntax is correct? ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: Please stop using the word...
    ... BigDog wrote: ... > who are you refering to but has some ... Jerry ... Prev by Date: ...
    (rec.collecting.coins)