Recent Articles
- Simple Web Crawler in Perl, Started by blitzcoder in Perl
- Twitter Controlled RAT (Mobile accessible), Started by gotroot in Perl
- Multiple Choice Questions in PERL, Started by ungalnanban in Perl
- Ceil/Floor/Round in Perl, Started by pradeep in Perl
- Access Amazon S3 Service using Perl, Started by pradeep in Perl
Similar Articles
- Web Design Tricks and Tips, Started by daworm in Web Design
- Introduction To Hashes In Perl, Started by pradeep in Perl
- Windows XP Tricks & Tips, Started by pradeep in Windows
- SSH Tips and Tricks, Started by Febian in Web Development
Preserve Add Order
Perl doesn't guarantee the order of the elements of hash, they may be in a different order everytime you access the hash. It's a much wanted, rather expected behaviour that I get my elements in the order I added them to the hash. The Tie::IxHash module helps us out of this problem, all we need to do it to tie the has to this module, after which you'll find the hash elements in the same order you has added them.
Here's a simple demonstration.
Code: Perl
Use 2 Arrays For Keys & Values Of A Hash
Code: Perl
Some might be confused with the "@..{..}" notation, it's the notation for accessing a hash slice, by which you can access a range/collection of hash keys at once.
A very useful implementation of hash slice is while fetching rows using DBI module. Use hash slices we can get a hash of the record row, much like the PHP equivalent mysql_fetch_row, which can be used to fetch a associative array.
Sorting Hashes
By keys:
Unlike an array you cannot sort a hash, cause Perl uses it's own algorithm the order of hash elements which is not at all predictable. So, the trick is to get the keys of a hash and sorted them insted to get the desired results.
Code: Perl
By values:
Like the above example, here we will again be using the keys but differently. We use the string comparison operator "cmp" and <=> for interger comparison.











Yet to provide details about himself




Linear Mode

