Perl: Hash variables

Declaring a new hash

    my %desc;

This let perl know that you plan on using a hash with the name desc

Adding a element

    $desc{"key1"} = "data for key 1";

Adds the value "data for key 1" into the hash desc, with a key "key1".

Iterating through a hash

Environment variables are passed to perl via the ENV hash. The example below lists all environment variables

foreach $key (sort keys %ENV) {
    print "$key = $ENV{$key}\n";

Published: Thursday, 21 October 2004