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: Indexing service server 2008 iis7.0 error
    ... I do not know where I got that syntax but it does not work in Server 2008. ... "Jerry C" wrote: ... Dim daIS As New OleDbDataAdapter ...
    (microsoft.public.data.oledb)
  • 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: Join Query Expression
    ... Jerry, thanks for the response. ... I am having trouble with the syntax though. ... manually fix the problem records. ... Table 2 has employee name in this order: ...
    (microsoft.public.access.queries)
  • 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)