Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Help ! accessing arrays of arrays problem -still get confused

Expand Messages
  • Charles K. Clarkson
    ... ( . . . ) is a returns a list. [ . . . ] returns an array. my @a = qw(apple orange lemon pearch); my @b = qw(asparagus corn peas); my @c = qw(ham chicken);
    Message 1 of 5 , Apr 28, 2001
    • 0 Attachment
      : thanx for your input but still get confused.
      : As my understanding, if I define @all = (@a,@b,@c), it means @a,@b
      : and @c has been flatted to new array @all. So I can not access @all by
      : $all[0][2] because @all is just one dimension array.
      :
      : My question is why can I still access one dimension array @all by $all[0]
      : [2] ?
      :
      : I tested my code and got diffrent output.
      :
      : Code 1 :
      : *********************************
      : #!/usr/bin/perl
      : @a = qw(apple orange lemon pearch);
      : @b = qw(asparagus corn peas);
      : @c = qw(ham chicken);
      : @all = (@a,@b,@c);
      : print $all[0][2]; #line 6 is here
      :

      ( . . . ) is a returns a list. [ . . . ] returns an array.

      my @a = qw(apple orange lemon pearch);
      my @b = qw(asparagus corn peas);
      my @c = qw(ham chicken);
      my @all = [@a,@b,@c];
      print $all[0][2]; # line 6 is here


      HTH,
      Charles K. Clarkson
    Your message has been successfully submitted and would be delivered to recipients shortly.