Perl Hash Let’s see on couple examples how we can use perl hash. First we need to know that perl hash value is accessible via key. Therefore:
$myhashvalue = $hash($key)
Creating perl hash
#!/usr/bin/perl $perl_hash{one} = Using; $perl_hash{two} = perl; $perl_hash{three} = hash; print $perl_hash{three} . "\n";
First we have create a $perl_hash to hold three values “Using perl hash” to be accessible via three keys”one two three”, respectively. Then we user print to print a hash value using key “three”. Use join to print all hash key/value pairs:
#!/usr/bin/perl $perl_hash{one} = Using; $perl_hash{two} = perl; $perl_hash{three} = hash; print join(" ", %perl_hash) . "\n";
Print all perl hash values
#!/usr/bin/perl $perl_hash{one} = Using; $perl_hash{two} = perl; $perl_hash{three} = hash; while(($key, $value) = each(%perl_hash)) { print "$value\n"; }