#!/usr/bin/perl
#File: blesstest

package foo;       # package foo becomes the current package
$foo_var = "FOO!"; # a scalar in package foo::
sub display {      # a subroutine in package foo::
  return $foo_var;
}

package bar;       # package bar becomes the current package
$bar_var = "BAR!"; # a scalar in package bar::
sub display {      # a subroutine in package bar::
  return $bar_var;
}

package main;      # package main becomes the current package
#begin test section
#Uncomment any 3 grouped lines of executable code in this section

#This works!!!
$myref = {};                    #creates a reference to an anonymous hash
$$myref{"fourteen"} = 14;
print $$myref{"fourteen"},"\n";

#So does this!
#$myref = [];                   #creates a reference to an anonymous array
#$$myref[2] = 14;
#print $$myref[2],"\n";

#So does this!
#$myref = \$what;               #creates a reference to a scalar
#$$myref = 14;
#print $$myref,"\n";

#So does this!
#$myref = sub {print "14\n";};  #creates a reference to an anonymous subroutine
#&$myref();

#end test section

$myref2 = bless ($myref, foo);  #reference is returned by bless for assignment
print $myref->display(),"\n";

# try commenting the following one line when any group above is active
bless $myref, bar;
print $myref->display(),"\n";

print "\$myref is $myref, and \$myref2 is $myref2\n";

# uncomment the appropriate line below
print $myref2->display(),"\n";
#print $$myref2{"fourteen"},"\n";
#print $$myref2[2],"\n";
#print $$myref2,"\n";
#&$myref2;

