Perl hash
Last Updated on Saturday, 31 July 2010 08:01 Saturday, 31 July 2010 07:28
| Article Index |
|---|
| 1. Creating perl hash |
| 2. Print all perl hash values |
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)
1. 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";
2. 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";
}















