hashes.pl %(hash related)

A UNIX Command
$cat hashes.pl
# Simple hash constructs
$fred{"with"} = "without";
$fred{"this"} = "that";
$fred{"mountain"} = "valley";
$fred{"left"} = "right";
print qq/$fred{"this"}n/;
@keys = keys(%fred);
print "Keys are @keysn";

# Initializer for %yard.
%yard = ( red => 'brick',
          blue => 'sky',
          green => 'grass',
          yellow => 'dandelion' );
print "$yard{'blue'} $yard{'yellow'}n";

$perl hashes.pl
that
Keys are left mountain with this
sky dandelion
$


UNIX Explanation
Variables  whose   names  begin  with  %  are   hashes,  which  are
essentially arrays subscripted by  strings. As with arrays, %sue is
a hash, and it is a different variable from $sue, though members of
%sue are  selected by  $sue{$s}.  The built-in  function keys(%sue)
returns an array of all the keys (subscripts) of the hash %sue.

http://sandbox.mc.edu/~bennet/perl/leccode/var3_pl.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s