Perl Hashes - What is?
Perl Hash:
Perl hash is un-ordered collection of elements, hash will not retrieve elements based on its index value instead it retrieves elements based on keys.
Hash will be created using curly {} braces and ( ) parenthesis and hash keys will never have repeated elements because it is unique formatting records.
Based on keys able to query faster results in large data. sort will be used for ordered and un-ordered results.and we can also perform numeric sorting on same results.
Large and improvised data structure can be performed using hash.
like,
1.Hash of Hash
2.Hash of Array
Hash of Hash will have keys of keys and its values.
For Example:
Best Schools in Salem District
%Best-schools-salem=>{
rural1 => { GHSS-TVS,
GHSS-ATR,
GHSS-GVL },
rural2 => { GHSS-ABC,
GHSS-FOR,
GHSS-RTR },
rural3 => { GHSS-OCR,
GHSS-ATM,
GHSS-MAR }
}
Based on '%Best-schools-salem' hash we can get best schools name very easily,like that
Hash of array will have keys of arrays and its values.
For Example:
Best Schools in Salem District
%Best-schools-salem=>{
rural1 => [ GHSS-TVS,
GHSS-ATR,
GHSS-GVL ],
rural2 => [ GHSS-ABC,
GHSS-FOR,
GHSS-RTR ],
rural3 => { GHSS-OCR,
GHSS-ATM,
GHSS-MAR }
}
Based on '%Best-schools-salem' hash we can get best schools name very easily, but the Difference is hash of hash will have unordered elements in its values but hash of array will have ordered and indexed values in its array elements.
Hash can be accessed by the following ways,
1.Based on Keys
2.Based on Values
3.hash slice based access
Hash Can be created by following ways,
Method 1: [Empty Hash]
Method 2:
Method 3:[Automatic Creation]
Method 4:
Method 5:
Method 6:
Perl hash is un-ordered collection of elements, hash will not retrieve elements based on its index value instead it retrieves elements based on keys.
Hash will be created using curly {} braces and ( ) parenthesis and hash keys will never have repeated elements because it is unique formatting records.
Based on keys able to query faster results in large data. sort will be used for ordered and un-ordered results.and we can also perform numeric sorting on same results.
Large and improvised data structure can be performed using hash.
like,
1.Hash of Hash
2.Hash of Array
Hash of Hash will have keys of keys and its values.
For Example:
Best Schools in Salem District
%Best-schools-salem=>{
rural1 => { GHSS-TVS,
GHSS-ATR,
GHSS-GVL },
rural2 => { GHSS-ABC,
GHSS-FOR,
GHSS-RTR },
rural3 => { GHSS-OCR,
GHSS-ATM,
GHSS-MAR }
}
Based on '%Best-schools-salem' hash we can get best schools name very easily,like that
Hash of array will have keys of arrays and its values.
For Example:
Best Schools in Salem District
%Best-schools-salem=>{
rural1 => [ GHSS-TVS,
GHSS-ATR,
GHSS-GVL ],
rural2 => [ GHSS-ABC,
GHSS-FOR,
GHSS-RTR ],
rural3 => { GHSS-OCR,
GHSS-ATM,
GHSS-MAR }
}
Based on '%Best-schools-salem' hash we can get best schools name very easily, but the Difference is hash of hash will have unordered elements in its values but hash of array will have ordered and indexed values in its array elements.
Hash can be accessed by the following ways,
1.Based on Keys
2.Based on Values
3.hash slice based access
Hash Can be created by following ways,
Method 1: [Empty Hash]
%has = ( );
Method 2:
%hash = ( );
$hash{a}='one'; $hash{b}='two'; $hash{c}='three';
Method 3:[Automatic Creation]
$hash{a}='one'; $hash{b}='two'; $hash{c}='three';
Method 4:
%hash=('a','one','b','two','c','three');
Method 5:
%hash=qw(a one b two c three);
Method 6:
%hash=qw(a => one , b => two, c => three);
Labels: perl hash, what is hash
0 Comments:
Post a Comment
Note: only a member of this blog may post a comment.
<< Home