Alfred Wong's Programming Showcase
About me Links HTML COBOL Java JavaScript Perl PHP
#!/usr/bin/perl -w                              # Unix
#!c:/perl/bin/perl -w                           # Windows

%hash = (1 => 2,                                # 1 2
         2 => 3,                                # 1 2 2 3
         3 => 4);                               # 1 2 2 3 3 4

print "Content-type: text/html\n\n";            # Need blank line after this line!
print('%hash = ', %hash, "<br>\n");

$hash{2} = 5;                                   # 1 2 2 5 3 4
print('After $hash{2} = 5: ', %hash, "<br>\n");

$hash = 6;                                      # different variable than %hash or @hash!

%hash = reverse(%hash);                         # 2 1 4 3 5 2
print('After reverse(%hash): ', %hash, "<br>\n");
print("Delete keys 1-4<br>\n");

for ($i = 1; $i < 5; $i++)
{
  delete($hash{$i});
  print "$i: ";
  print(%hash);
  print "<br>\n";
}
© 2004 Alfred Wong