#!/opt/local/bin/perl -w #you'll need to replace the above with the path #to your perl interpreter. #use strict; #uncomment me later! #this demonstrates why it's good to use strict. $ref = 'aaa'; $aaa = 99; @aaa = (1,2,3); #now watch as $ref points to different variables, #depending on the context. print "scalar context: $$ref\n"; print "array context: @$ref\n"; #what is $ref, anyway? print "\$ref: $ref\n"; #here's an example of the same thing using a hash instead of a ref. #this is how I first discovered it. $hash{aaa} = "aaa"; print "hash value in scalar context: $hash{aaa}\n"; print "hash value in array context: @{$hash{aaa}}\n"; #Pretty weird stuff. It all makes sense once you learn symbolic #references, which were a big part of perl4, but they can be ambiguous #depending on context, so if you use strict, you can bar them.