in reply to Re: Problem with traversing a two dimensional array (to create an arrayref use [ ] )
in thread Problem with traversing a two dimensional array

Hmm, the solution is correct but, in my view, the explanation seems to miss the main point: the main point is that, to construct an AoA, what needs to be pushed onto the larger array is not a list nor an array, but an array reference, and the sqare bruckets acts in this case as an array reference constructor.
  • Comment on Re^2: Problem with traversing a two dimensional array (to create an arrayref use [ ] )

Replies are listed 'Best First'.
Re^3: Problem with traversing a two dimensional array (to create an arrayref use [ ] )
by Anonymous Monk on Jan 16, 2014 at 07:44 UTC

    Hmm, the solution is correct but, in my view, the explanation seems to miss the main point:

    I don't think so Laurent_R, that is impossible
    The error message says Can't use string(".") as an ARRAY ref
    My answer title says (to create an arrayref use [ ] )
    My answer says split returns a list, to make an array you need [ 'square' , 'brackets' ]

    your view is tiny

      split returns a list, to make an array you need 'square' , 'brackets'

      Well, this:

      (split /$separator/, $line)
      gives you an array, on which you can use an index to find one element, for example:
      my $third_elmnt = (split /$separator/, $line)[2];
      On the other hand, this:
      [split /$separator/, $line];
      does not give you an array, but an arrayref i.e. a single scalar. And an arrayref is what you need to oush onto an array if you want to build an AoA.

      You probably know all that, I was only objecting to the fact that this was not made very clear in my humble opinion.

        gives you an array, on which you can use an index to find one element, for example:

        No, a list is a list and not an array, perl lets you index a list, it doesn't make a list an array

        On the other hand, this: does not give you an array, but an arrayref i.e. a single scalar. And an arrayref is what you need to oush onto an array if you want to build an AoA.

        When you make an arrayref, what is that reference pointing to?
        An array right?
        so creating an arrayref creates an array (it make an array )

        You probably know all that, I was only objecting to the fact that this was not made very clear in my humble opinion.

        Well, if you wrote something like:
        to clarify
        to elaborate
        to make more clear
        to make more clear some details
        to make more clear some subtle details
        ... some kind of words other than ... miss the main point

        I probably wouldn't have responded

        Correct corrections are welcome ; elaborations are usually welcome (if they don't go off topic from main thread too much)

        wrong corrections not so much; they call the duty