[kw-pm] part 1, question about dereferencing

Robert P. J. Day rpjday at crashcourse.ca
Thu Feb 24 10:44:48 PST 2011


  on short notice, i'm reviewing my dereferencing so let me ask if i
have a grip on the following.  here's the code:

===== board =====

# How can I print the middle element (22)?

my @board = (
        [11, 12, 13],
        [21, 22, 23],
        [31, 32, 33]
);

print "@board.\n";              # entire board (list of refs)
print "$board[1].\n";           # second elt (anonymous array)
print "@{$board[1]}.\n";        # actual second row
print "$board[1]->[1].\n";      # middle element
print "$board[1][1].\n";        # middle element using shortcut

===== end board =====

  long story short, "@board" is obviously an array of three array
references, and i just wanted to print various ways of dereferencing
things to get to the middle element (22).

  does all of the above look sane?  just from the comments, it should
be clear what i'm trying to demonstrate, one step at a time.  does all
of the above make sense?

rday

-- 

========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================


More information about the kw-pm mailing list