You have to understand that a hash is an associative array, why associative? because each one of its indices (keys) is made to link to a value, the key is embraced within {} and the values can be assigned to a key in many different ways. Since a hash is a type of an array (arrays are essentially lists ) then list functions like reverse or sort can be performed on a hash (their behavior varies between arrays and hashes), however, a hash has its own set of functions as well, like each, keys,values. Read more about hashes at http://perldoc.perl.org/search.html?q=hash.

What's in a hash value?, a value can be as simple as a number or a string or a single scalar, or can progressively take an advanced shape, in that case the entire hash represents an advanced data structure.

If you have an array of 3 elements, you can access the second element directly by giving its position (index), this is called subscripting..

@array = (0,1,2); print $array[1]; ^
The same thing can be done to a hash, you want to access a given value, you give its position (key):
my %hash = (fruit=>banana, veg=>'cucumber'); print $hash{fruit}; ^
Why $ precedes a hash or an array when we're subscripting?, because in Perl, a single subscript is a single scalar so it makes sense that it is treated as such, perl gives you a warning in case you tried print @array[1]; and tells you that it is better written as print $array[1];

Data structures can be an amalgam of arrays, hashes, scalars so that one hash key can link to a value that is a hash of different keys and these different keys in the linked-to hash can themselves again be linking to an array for instance. The flexibility is that you can define the data structure yourself and build up on it.

Check the Tutorials for:

While this list is not exhaustive, you can refer to Reviews->Book Reviews and avail of the Super Search utility.. Another rich resource is the Perl Documentation, which you can also access from your terminal as well by typing %perldoc at your command prompt and from there you can learn how to make use of the documentation that is packaged with your version of Perl.

While I am just aiming to show you -in context to your question- the different types of resources that you can always refer to I have to include the Comprehensive Perl Archive Network (CPAN), this is a source of Perl modules, libraries and many other useful code.

Hang in there and have a nice Perl journey :) ...


Excellence is an Endeavor of Persistence. A Year-Old Monk :D .

In reply to Re: Not getting this assignment ... by biohisham
in thread Not getting this assignment ... by mvkarthik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.