#!/usr/bin/perl -w ####################################################### # class3_01_hash1 # # demo how one assigns a list of key-value pairs to # a hash, and show that they're really there # # modified by Sharon Tuttle from "Learning Perl", # by Schartz and Phoenix # # last modified: 4-13-03 ####################################################### %order_totals = ("chocolate", 13, "hamburger", 10, "tofu dog", 12); print "\$order_totals\{\"chocolate\"\}: $order_totals{\"chocolate\"}\n"; print "\$order_totals\{hamburger\}: $order_totals{hamburger}\n"; print "\$order_totals\{'tofu dog'\}: $order_totals{'tofu dog'}\n"; # show that variable interpolation doesn't work on hashes... # this just prints the string %order_totals print "%order_totals\n"; # hey, but you CAN just give the has to print --- and it'll # print a string depiction of it; (quick'n'sleazt, though --- # no spaces...!) print %order_totals, "\n"; # CAN "unwind" into an array and print that array, though: @hold_order_totals = %order_totals; print "@hold_order_totals\n"; # another experiment: print "<@{%order_totals}>\n"; # and one more... print @{%order_totals}, "\n"; print @(%order_totals), "\n"; # end of class3_01_hash1