Sunday, January 2, 2011

Perl: Hash Hacking Functions

Assigning $countries{PT}='Portugal';
Deleting delete $countries{NL};

Accessing Your Hash
Assuming you keep the same %countries hash as above, here are some useful ways to access it:
All the keys print keys %countries;
All the values print values %countries;
A Slice of Hash :-) print @countries{'NL','BE'};
How many elements ? print scalar(keys %countries);
Does the key exist ? print "It's there !\n" if exists $countries{'NL'};

No comments: