|
Academic Work Personal
|
Perl /
Hash
QuestionHow to use a hash? AnswerExample 1Creating and filling a hash.
my %hashTable = (); # empty hash
$hashTable{'A'} = 'Aladar';
$hashTable{'B'} = 'Bela';
$hashTable{'C'} = 'Cecil';
Example 2Printing key - value pairs.
while ( my ($key, $value) = each(%hashTable) ) {
print "$key => $value\n";
}
A => Aladar C => Cecil B => Bela Example 3Check if a hash value is defined.
if (defined $hashTable{'B'}) {
print "B is defined\n";
}
else {
print "B is NOT defined\n";
}
if (defined $hashTable{'D'}) {
print "D is defined\n";
}
else {
print "D is NOT defined\n";
}
B is defined D is NOT defined More info |
![]() anime | bash | blogs | bsd | c/c++ | c64 | calc | comics | convert | cube | del.icio.us | digg | east | eBooks | egeszseg | elite | firefox | flash | fun | games | gimp | google | groovy | hardware | hit&run | howto | java | javascript | knife | lang | latex | liferay | linux | lovecraft | magyar | maths | movies | music | p2p | perl | pdf | photoshop | php | pmwiki | prog | python | radio | recept | rts | scala | scene | sci-fi | scripting | security | shell | space | súlyos | telephone | torrente | translate | ubuntu | vim | wallpapers | webutils | wikis | windows Blogs and Dev. * Ubuntu Incident Places Debrecen | France | Hungary | Montreal | Nancy Notes Hobby Projects * Jabba's Codes Quick Links [ edit ] |