On Aug 19, Dave Adams said:

In the code below, I thought $array[2] and $array->[2] were different
but they give me the same result.

Any explaination for this?

my @array = (1,2,3);
my $array [EMAIL PROTECTED];
print ref($array);
print $array[2];
print $array->[2];

The constructs $this[2] and $this->[2] are different. The first is getting an element from @this, the second is getting an element in the array referred to by $this.

You have made the "mistake" of naming your array and your array REFERENCE the same things.

  my @array = (1, 2, 3);
  my $ref = [EMAIL PROTECTED];

  print $array[2];    # '3'
  print $array->[2];  # nothing, $array doesn't exist!
  print $ref[2];      # nothing, @ref doesn't exist!
  print $ref->[2];    # '3'

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to