

   my $bar = 4;                # a scalar
   my $foo = \$bar;            # a pointer to a scalar
   print $$bar;                # de-reference the pointer

   my @array = (10,11,12);     # an array
   my $ptr   = \@array;        # pointer to an array
   print " 0th array is '" . $$ptr[0]  . "'\n";           # print first element
   print " 0th array is '" . $ptr->[0] . "'\n";           # same thing using ->
   print $ptr->[0];            

   print " ref(bar) is '" . ref($bar) . "'\n";            # not a reference
   print " ref(foo) is '" . ref($foo) . "'\n";            # ref to scalar
   print " ref(ptr) is '" . ref($ptr) . "'\n";            # ref to array



   # double a number and return it.
   sub double {
     my ($x) = @_;
     return 2*$x;
   }

   my $subptr = \&double;      # The special symbol for a sub is "&".

   # invoke a pointer to a subroutine.
   print "double 2 is '" . $subptr->(2) . "'\n";

   # or (another way to do the same thing)
   print "double 2 is '" . &{$subptr}(2) . "'\n";


   # An pointer to an anonymous array.  Note the [] rather than ().
   my $arrayptr = [10,11,12];
   $arrayptr->[12] = 17;           # fill in a value.

   # A pointer to an anonymous subroutine.
   my $dubwa = sub { my ($x)=@_; return 2*$x; };
   my $answer = $dubwa->(16);                    # Find double 16.
