pcouderc has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
1- What is the difference between
my @arr = ['a','b','c']; and my @arr = ('a','b','c');
?
2- In what doc am I supposed to find the answer at this question?

Thank you
Pierre Couderc

Replies are listed 'Best First'.
Re: Lost in doc
by sauoq (Abbot) on Aug 11, 2003 at 09:55 UTC
    1- What is the difference between
    my @arr = ['a','b','c']; and my @arr = ('a','b','c');
    ?

    The first line creates an array with one element: a reference to an anonymous array with 3 elements, 'a', 'b', and 'c'.

    The second line creates an array with 3 elements, 'a', 'b', and 'c'.

    2- In what doc am I supposed to find the answer at this question?

    In addition to the ones other have mentioned, you should probably read perldoc perldsc, the data structure intro and perldoc perllol, the "arrays of arrays" tutorial which explains in great detail the structure you created in your first example. In the future, you may help yourself to answer questions like your second one by reading perldoc perltoc, the table of contents.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Lost in doc
by snadra (Scribe) on Aug 11, 2003 at 09:12 UTC
    Hello,

    if you are using square brackets, you are creating a reference. To create an anonymous array ref do this:
    $arrayref = ['a', 'b', 'c'];
    To find out more about references, read:
    perldoc perlref
    Or the short version of perlref, wich only contains the very neccessary information:
    perldoc perlreftut

    snadra
Re: Lost in doc
by antirice (Priest) on Aug 11, 2003 at 10:02 UTC

    After the second, @arr contains three elements. After the first, @arr contains one element, which would be an arrayref.

    #!/usr/bin/perl -w use strict; use Data::Dumper; my @a = [ qw(a b c) ]; print "\@a contains ",scalar @a," element(s) and looks as such:$/",Dum +per(\@a); my @b = ( qw(a b c) ); print "\@b contains ",scalar @b," element(s) and looks as such:$/",Dum +per(\@b); __DATA__ output: @a contains 1 element(s) and looks as such: $VAR1 = [ [ 'a', 'b', 'c' ] ]; @b contains 3 element(s) and looks as such: $VAR1 = [ 'a', 'b', 'c' ];

    Some places to look: perldata, perldsc, perllol, and qw. Hope this helps.

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1

Re: Lost in doc
by slayven (Pilgrim) on Aug 11, 2003 at 09:08 UTC
    perldata that is.
    Search for "List value constructors"

    --
    trust in bash
    but tie your camel
Re: Lost in doc
by pcouderc (Monk) on Aug 11, 2003 at 11:34 UTC
    Thank you all
    Now I am less lost!
    Pierre Couderc